package cz.moneta.test.regression.channels.branch.archive;

import cz.moneta.dataprepare.CustomerDataPrepare;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.loans.VER017_S001_SecondBankerVerificationStatusPage;
import cz.moneta.test.dsl.ufo.banka.pages.search.HLO001_S001_ClientSearchPage;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.BankaUtils;
import cz.moneta.test.dsl.util.data.client.Employer;
import cz.moneta.test.harness.annotations.JiraTestCase;
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;

import static cz.moneta.test.dsl.ufo.banka.pages.loans.VER017_S001_SecondBankerVerificationStatusPage.APPLICATION_ID_KEY;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo;
import static cz.moneta.test.harness.annotations.Environment.EDU;
import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@Disabled
@TestScenario(name = "Teller must be able to create a new customer with a new loan")
public class CreateNewCustomerWithLoan extends CustomerDataPrepare {

    @TestCase(name = "Bank teller is able to login and create a new customer with a new loan", environments = {TST1, PPE, EDU})
    @JiraTestCase(id = "POB-T19508")
    public void createNewCustomerWithLoan(Harness harness, @Key(ufo.banka.banker) Credentials banker, @Key(ufo.banka.secondBanker) Credentials secondBanker) {
        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        int loanAmount = 50000;
        int numberOfInstallments = 60;
        String coApplicantBirthNumber = harness.getConfig("branch.squad.rc.client");
        nonClient.withEmployer(Employer.builder().ico("75643375").name("Petr Ráab").phoneNumber("756456854").build());

        HLO001_S001_ClientSearchPage firstInstance = harness.withUfoSecondInstance()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsSecondBanker(secondBanker))
                .storeBankerName();

        String bankerName = BankaUtils.formatUserNameForVerification(harness.get("BANKER_NAME"));

        VER017_S001_SecondBankerVerificationStatusPage secondInstance = harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(banker))
                .then(bankaTasks.search().findByCif(newCustomerCif))
                .storeClientFullName()
                .then(bankaTasks.sharedTasks().storeClientDetailInfo(harness))
                .then(bankaTasks.newProduct().createNewCurrentAccount("Tom Plus"))
                .then(bankaTasks.expresTasks().createExpressLoan(coApplicantBirthNumber, loanAmount, numberOfInstallments, nonClient, bankerName));

        firstInstance
                .then(bankaTasks.newProduct().verifyApplicationSignature(harness.get(APPLICATION_ID_KEY)));

        secondInstance
                .then(bankaTasks.newLoanApplication().finishExpressLoan());
    }
}
