package cz.moneta.test.regression.creditdistribution.loans;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.loans.expres.LoanData;
import cz.moneta.test.dsl.ufo.banka.pages.loans.expres.NEP006_S001_ExpressScoringResultPage;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
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.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;

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


@TestScenario(name = "Expres loan regression tests")
public class ExpresLoanTests {
    private BankaTasks bankaTasks;
    private LoanData data;

    @BeforeEach
    public void setUp(Harness harness) {
        bankaTasks = harness.tasks().ufo().banka();
        data = bankaTasks.expresTasks().expressLoanDataPreparationTasks().preBuildLoanData();
        bankaTasks.expresTasks().expressLoanDataPreparationTasks().prepareClient(data.getClient());
    }

    @TestCase(name = "Cloan Expres OM - verifikace 4 očí - happy flow")
    @JiraTestCase(id = "CLOANS-T886", project = "Cloans")
    public void expresLoanTest_happy(Harness harness, @Key(banker) Credentials credentials) {
        data.setAmount(99000);
        data.setTerm(72);
        data.setInsurance(true);
        data.setInsuranceName("Poj. schopnosti splácet 2025");
        NEP006_S001_ExpressScoringResultPage page = harness.withUfo().openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.expresTasks().expresLoanE2ETask(data));
        Assertions.assertEquals("Úvěr načerpán", page.getAppStat());
    }

    @AfterEach
    public void tearDown(Harness harness) {
        harness.store("reports.tmfj.execution.comment", bankaTasks.expresTasks().housingLoanLoggingTasks().getLogExpresDataString(data));
    }
}
