package cz.moneta.test.regression.risk.applications.existingclient;

import cz.moneta.test.dataprepare.risk.DefaultLoan;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.util.code.lists.HCisAllStavZadosti;
import cz.moneta.test.dsl.util.code.lists.HCisDoklady;
import cz.moneta.test.dsl.util.data.client.Address;
import cz.moneta.test.dsl.util.data.client.Employer;
import cz.moneta.test.harness.annotations.Environment;
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.BeforeEach;

import java.util.List;

import static cz.moneta.test.dsl.util.credentials.Keys.ufo.banka.banker;

@TestScenario(name = "Regression test - Expres Loan application for an existing client")
public class ExpressLoanApplicationExistingClient extends DefaultLoan {

    private final Employer EMPLOYER = new Employer("Pianoclassic s.r.o.", "17466865", Address.builder().street("Hvězdova").descriptiveNumber("1716").orientationNumber("2b").city("Praha").zip("14000").country("CZ").build(), "733303555");
    @BeforeEach
    public void initApplicant() {
        applicant.withEmployer(EMPLOYER);
        applicant.withHomeIncome(150000);
        applicant.withOtherLoanPayments(200);
    }

    @TestCase(name = "Regression test - Expres Loan application for an existing client", environments = {Environment.TST1})
    @JiraTestCase(id = "RISK-T2072")
    public void newClientWithExpressLoanApplication(Harness harness, @Key(banker) Credentials credentials) {
        String birthNumber = "9803148201";

        HKO101_S001_MainClientPage ufoWindow = bankaTasks.newClient().openUfoAndFindClient(harness, credentials, birthNumber);
        List<String> applList = harness.tasks().nasDb().getAllPendingApllicationsForClient(birthNumber);
        ufoWindow = harness.tasks().ufo().banka().expresTasks().cancelAllPendingApplications(applList, ufoWindow);
        ufoWindow.then(bankaTasks.expresTasks().createNewExpressApplicationWithExisting(applicant, LOAN_AMOUNT, TERM, HCisAllStavZadosti.DOCUMENTS_REQUIRED, HCisDoklady.RP));
    }

}
