package cz.moneta.test.smoke.sb;

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

import static cz.moneta.test.dsl.util.task.sb.SbTasks.PIN;

@TestScenarioWithOrder(name = "Smart banking smoke tests")
public class SmartBankingSmokeTests {

    @Order(1)
    @TestCase(name = "Install and open SB test")
    public void openSB(Harness harness) {
        harness.withSB()
                .onActivationPage();
    }

    @Order(2)
    @TestCase(name = "Activate new user in IB")
    @JiraTestCase(id = "TEA-T31")
    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();
    }

    @Order(3)
    @TestCase(name = "Login to SB")
    @JiraTestCase(id = "TEA-T28")
    public void mobileLogin(Harness harness) {
        harness.withSB()
                .onLandingPage()
                .typePinAndContinue(PIN);
    }
}
