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.cards.credit.ProductType;
import cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.NKK006_S001_CreditCardScoringResultPage;
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.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 Credit Card")
public class ExpressLoanCreditCard extends DefaultLoan {

    @TestCase
    public void newClientWithExpressLoanAndCreditCard(Harness harness, @Key(banker) Credentials credentials, @Key(secondBanker) Credentials secondCredentials) {
        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));

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

        firstBankerWindow.then(bankaTasks.expresTasks().finishAccountCreationAfterSecondBankerSignature(HCisAllStavZadosti.LOAN_DRAWN))
                .then(bankaTasks.cardsServicing().creditCards().createNewCreditCardApplicationWithPrefilledData(LOAN_AMOUNT, HCisAllStavZadosti.APPLICATION_CONDITIONALLY_APROVED))
                .then(bankaTasks.cardsServicing().creditCards().createAccountsForNewCreditCardWithExistingIbAndBu(harness.get(NKK006_S001_CreditCardScoringResultPage.APP_ID_STORE), LOAN_AMOUNT))
                .then(bankaTasks.cardsServicing().creditCards().activateCreditCardWithoutSignatureSelect(ProductType.MONEYCARD_SMART.getValue(), "OP", applicant.idCardNumber()));
    }
}