package cz.moneta.test.regression.channels.digital.ml.hypos;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.hypos.contractPrepare.data.ContractDataPrepare;
import cz.moneta.test.dsl.hypos.contractPrepare.process.ContractProcessPrepare;
import cz.moneta.test.dsl.hypos.enums.HyposProfile;
import cz.moneta.test.dsl.hypos.tasks.HyposTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.hypos.HyposContract;
import cz.moneta.test.harness.annotations.*;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.Disabled;

@NonConcurrentTestScenario(name = "End to end Hypos test scenario")
public class ContractTests {

    @TestCase(name = "Create and draw new contract (product Flexible mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T1159")
    public void tcCreateAndDrawFlexibleContract(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/simpleContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract with life insurance (product Flexible mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T2236")
    public void tcCreateAndDrawFlexibleContractWithCardif(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/cardif1ContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillLifeInsuranceData(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract with two clients (product Flexible mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T2407")
    public void tcCreateAndDrawFlexibleContractWithTwoClients(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/twoClientsContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract (product American mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T1429")
    public void tcCreateAndDrawAmericanContract(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("americanMortgage/simpleContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract with life insurance (product American mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T2237")
    public void tcCreateAndDrawAmericanContractWithCardif(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("americanMortgage/cardif1ContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillLifeInsuranceData(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract with two clients (product American mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T2610")
    public void tcCreateAndDrawAmericanContractWithTwoClients(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("americanMortgage/twoClientsContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract (product Variable Mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T1430")
    public void tcCreateAndDrawVariableContract(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("variableMortgage/simpleContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create and draw new contract with two clients (product Variable mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T2611")
    public void tcCreateAndDrawVariableContractWithTwoClients(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("variableMortgage/twoClientsContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create new contract until draw (product Flexible mortgage)", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T2612")
    public void tcCreateFlexibleContractUntilDraw(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        HyposTasks tasks = harness.tasks().hypos();
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/simpleContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.EMERGENCY))
                .then(tasks.searchAndOpenContractAndCheckState(hyposContract.getContractId(), "Úvěr podepsán"))
                .then(tasks.contractTasks().setLandAreaRegistrationDates())
                .then(tasks.contractTasks().setClientCurrentAccount(hyposContract.getCurrentAccountNumber()))
                .then(tasks.contractTasks().approveDrawingConditions());
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create new contract until draw with 2 clients and Cardif 1 (product Flexible mortgage)", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T3156")
    public void tcCreateAndDrawFlexibleContractWithTwoClientsAndCardif1(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/twoClientsCardif1ContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @Disabled("Temporarily disabled, replaced by another TC")
    @TestCase(name = "Create new contract until draw with 2 clients and Cardif 1+1 (product Flexible mortgage)", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T3155")
    public void tcCreateAndDrawFlexibleContractWithTwoClientsAndCardif2(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/twoClientsCardif2ContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @TestCase(name = "Create new contract until generate US with refinancing and money to account (product Flexible mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T3287")
    public void tcCreateAndDrawFlexibleContractWithRefinancing(Harness harness, @Key(Keys.ufo.banka.banker) Credentials banker) {
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/twoTranchesContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        contractProcessPrepare.generateAndSignLoanContractDocuments(hyposContract);
        contractProcessPrepare.createCurrentAccount(hyposContract, banker);
        contractProcessPrepare.fillDataAndCreateDrawRequest(hyposContract);
        contractProcessPrepare.verifyDrawRequest(hyposContract);
        contractProcessPrepare.doDrawInIcbs(hyposContract);
        contractProcessPrepare.checkContractDrawing(hyposContract);
    }

    @TestCase(name = "Create and draw new contract with employee (product Flexible mortgage) - E2E", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    @JiraTestCase(id = "ML-T3288")
    public void tcCreateContractUntilSignWithEmployee(Harness harness) {
        HyposTasks tasks = harness.tasks().hypos();
        ContractProcessPrepare contractProcessPrepare = new ContractProcessPrepare(harness);
        ContractDataPrepare contractDataPrepare = new ContractDataPrepare(harness);
        HyposContract hyposContract = contractDataPrepare.prepareContractData("flexibleMortgage/employeeContractData", harness);

        contractProcessPrepare.createNewHypokalkulacka(hyposContract);
        contractProcessPrepare.fillDataAndStartPrescoring(hyposContract);
        contractProcessPrepare.fillDataAndStartScoringManual(hyposContract);
        contractProcessPrepare.approveContract(hyposContract);
        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.EMERGENCY))
                .then(tasks.searchAndOpenContractAndCheckState(hyposContract.getContractId(), "Úvěr schválen"))
                .then(tasks.contractTasks().setEventsFlagsUw2());
    }
}