package cz.moneta.test.regression.channels.digital.sb;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ib.settings.smartbanka.DeviceRegistrationWizard;
import cz.moneta.test.dsl.mobile.smartbanking.landing.SmartBankingLoginKeyboard;
import cz.moneta.test.dsl.mobile.smartbanking.activation.FinishActivationView;
import cz.moneta.test.dsl.util.data.sb.FourPartToken;
import cz.moneta.test.dsl.util.task.ib.IbTasks;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.Disabled;

@TestScenario(name = "Registration SB in IB")
public class RegistrationSmartBankingUserTest {

    @Disabled(value = "Duplicate with smoke test SmartBankingSmokeTests#registrationSmartBankingUser")
    @TestCase(name = "Activate new user in IB")
    public void registrationSmartBankingUser(Harness harness, @Key("client.with.ib") Credentials credentials) {
        SmartBankingLoginKeyboard[] pin = {SmartBankingLoginKeyboard.KEY_1, SmartBankingLoginKeyboard.KEY_2, SmartBankingLoginKeyboard.KEY_3, SmartBankingLoginKeyboard.KEY_4};

        IbTasks ibTasks = harness.tasks().ib();
        String mobileKey = "12341234";

        DeviceRegistrationWizard currentActivation =
                harness.withIB()
                        .openLoginPage()
                        .then(ibTasks.loginWith(credentials, mobileKey))
                        .goToSettings()
                        .selectSmartBanka()
                        .startRegistration(harness, mobileKey);

        FourPartToken token =
                harness.data()
                        .fourPartToken(currentActivation.getDeviceRegistrationCode());

        FinishActivationView finishActivationOnMobile =
                harness.withSB()
                        .onActivationPage()
                        .activateSmartBanking()
                        .swipeToSecondActivationView()
                        .swipeToThirdActivationView()
                        .swipeToLastActivationView()
                        .chooseManualCodeEntry()
                        .typePartsOfCode(token.first(), token.second(), token.third(), token.fourth())
                        .tapOnContinueButton()
                        .enterPinUsingKeyboard(harness, pin)
                        .onConfirmView()
                        .enterPinUsingKeyboard(harness, pin)
                        .onFinishActivationView();

        currentActivation
                .afterMobileActivation()
                .typeSmsCode(mobileKey)
                .validateMobileKey()
                .onSuccessRegisteredMobileDevice();

        finishActivationOnMobile.tapOnCompleteActivationButton()
                .startUsingSmartBaking();
    }
}
