package cz.moneta.test.dataprepare.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.*;
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.Environment;
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;

@TestScenario(name = "Create new contract until draw")
public class DrawPrepare {

    @TestCase(name = "Create new contract until draw with job param", environments = {Environment.TST1, Environment.PPE, Environment.FVE})
    public void tcCreateContractUntilDraw(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(harness.getSystemOrConfigValue("yamlData"), 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());
    }
}