package cz.moneta.test.dataprepare.risk.multipleloans;

import cz.moneta.test.dataprepare.risk.DefaultLoan;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.loans.expres.NEP006_S001_ExpressScoringResultPage;
import cz.moneta.test.dsl.ufo.banka.pages.loans.expres.OPN008_S001_ExpressSignaturePage;
import cz.moneta.test.dsl.ufo.banka.pages.search.HLO001_S001_ClientSearchPage;
import cz.moneta.test.dsl.util.code.lists.HCisAllStavZadosti;
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 static cz.moneta.test.dsl.util.credentials.Keys.ufo.banka.banker;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo.banka.secondBanker;

@TestScenario(name = "Test for Risk Retail - Data preparation - client with Expres Loan and FlexiCredit")
public class ExpressLoanFlexiCredit extends DefaultLoan {

    @TestCase
    public void newClientWithExpressLoanAndFlexiCredit(Harness harness, @Key(banker) Credentials credentials, @Key(secondBanker) Credentials secondCredentials) {
        int flexiCreditLoanAmount = 30000;

        OPN008_S001_ExpressSignaturePage firstBankerWindow = bankaTasks.newProduct().createClientWithIb(harness, credentials, applicant)
                .then(bankaTasks.newProduct().createSBA())
                .then(bankaTasks.expresTasks().createNewExpressApplication(applicant, LOAN_AMOUNT, TERM, HCisAllStavZadosti.APPLICATION_CONDITIONALLY_APROVED))
                .then(bankaTasks.expresTasks().createAccountsForNewExpressUntilSignature(secondBankerName));

        HLO001_S001_ClientSearchPage secondBankerWindow = bankaTasks.newProduct().openUfoAndVerifyApplicationAsSecondBanker(secondCredentials, harness.get(NEP006_S001_ExpressScoringResultPage.APP_ID_STORE));

        firstBankerWindow = firstBankerWindow.then(bankaTasks.expresTasks().finishAccountCreationAfterSecondBankerSignature(HCisAllStavZadosti.LOAN_DRAWN))
                .then(bankaTasks.flexiCreditTasks().createNewFlexiCreditApplicationWithPrefilledData(flexiCreditLoanAmount, HCisAllStavZadosti.APPLICATION_CONDITIONALLY_APROVED))
                .then(bankaTasks.flexiCreditTasks().createAccountsForNewFlexiCreditWithExistingBuAndIbUntilSignature(flexiCreditLoanAmount, secondBankerName));

        secondBankerWindow.then(bankaTasks.newProduct().verifyApplicationSignature(harness.get(NEP006_S001_ExpressScoringResultPage.APP_ID_STORE)));

        firstBankerWindow.then(bankaTasks.flexiCreditTasks().finishAccountCreation(HCisAllStavZadosti.LOAN_ACCOUNT_OPEN));
    }
}