package cz.moneta.test.integration;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.CurrentAccountsEnum;
import cz.moneta.test.dsl.util.TestUtils;
import cz.moneta.test.dsl.util.data.client.NonClient;
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.AuthSupport;
import cz.moneta.test.harness.support.auth.Credentials;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.util.credentials.Keys.ufo.banka.banker;
import static cz.moneta.test.harness.support.data.GeneratorType.RC;

@TestScenario(name = "Teller must be able to crate a new customer with access to IB")
public class CreateNewCustomerWithIbEndToEnd {
    @TestCase(name = "Bank teller is able to login and create a new customer with access to IB, then check login to IB.")
    public void tc_bank_teller_is_able_create_new_customer_withAccess_to_ib(Harness harness) {
        BankaTasks withBanka = harness.tasks().ufo().banka();
        IbTasks withIb = harness.tasks().ib();
        String bankerUsername = AuthSupport.getCredentials(banker, harness).getUsername();

        String birthNumber = harness.generate(RC);
        NonClient nonClient = harness.data().newNonClient()
                .withBirthNumber(birthNumber)
                .withEmail(TestUtils.getEmailBasedOnRc(birthNumber));

        harness.withUfo()
                .openLoginPage()
                .then(withBanka.login().asBanker())
                .then(withBanka.login().turnSignpadOff())
                .then(withBanka.newClient().create(nonClient, bankerUsername))
                .then(withBanka.newPackagedProductTasks().ibWithMobileKeyAndCurrentAccount(nonClient, CurrentAccountsEnum.GENIUS_FREE_FLEXI));

        Credentials udebsCredentials = harness.tasks().wso2().idm().getIbCredentialsByRC(nonClient.birthNumber());

        harness.withIB()
                .openLoginPage()
                .then(withIb.loginWithUsernamePasswordAndMobileKey(
                        udebsCredentials.getUsername(),
                        udebsCredentials.getPassword(),
                        "12341234"))
                .onWelcomePage()
                .checkWelcomePageImageIsPresent();

        Assertions.assertTrue(StringUtils.isNotBlank(harness.get(HKO101_S001_MainClientPage.CLIENT_CIF_STORE_KEY)));
    }
}

