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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.hypos.enums.CadasterRequestType;
import cz.moneta.test.dsl.hypos.enums.DocumentTemplate;
import cz.moneta.test.dsl.hypos.enums.HyposProfile;
import cz.moneta.test.dsl.hypos.tasks.HyposDbTasks;
import cz.moneta.test.dsl.hypos.tasks.HyposTasks;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.hypos.pages.contract.realty.UnitDetailPage.CONTRACT_ID;

@TestScenario(name = "Cadaster tests")
public class CadasterTest {

    @TestCase(name = "Check search redoc")
    @JiraTestCase(id = "ML-T2609")
    public void tcCadasterSearchRedoc(Harness harness) {
        harness.withHypos()
                .openLoginPage()
                .switchToCadasterPage()
                .clickCadasterRequestPage()
                .selectFilterType(CadasterRequestType.OWNER_LIST)
                .clickSearchButton()
                .clickRedocDetail()
                .checkCadasterRequest();
    }

    @TestCase(name = "Check generated documents NnV and ZS")
    @JiraTestCase(id = "ML-T2883")
    public void tcCadasterGenerateNnvZs(Harness harness) {
        HyposTasks tasks = harness.tasks().hypos();
        String messageDocumentGenerationTimeout = "Document was not generated in 120 seconds interval.";
        String lvId = "2869";
        String lvCode = "729795";
        String lvFlatNumber = "592/3";

        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.EMERGENCY))
                .switchToRealtyPage()
                .then(tasks.valuationTasks().searchCadasterRedocDetail(lvCode, lvId))
                .clickFlatUnitDetail(lvFlatNumber)
                .getContractId(harness);

        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.EMERGENCY))
                .then(tasks.searchAndOpenContract(harness.get(CONTRACT_ID)))
                .clickProcessChecklist()
                .clickPledgeAgreementSubmit()
                .clickHomepage();

        Assertions.assertTrue(
                new HyposDbTasks(harness).contractDocumentFinished(harness.get(CONTRACT_ID), DocumentTemplate.DEPOSIT_PROPOSAL),
                messageDocumentGenerationTimeout
        );
        Assertions.assertTrue(
                new HyposDbTasks(harness).contractDocumentFinished(harness.get(CONTRACT_ID), DocumentTemplate.PLEDGE_AGREEMENT),
                messageDocumentGenerationTimeout
        );

        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.EMERGENCY))
                .then(tasks.searchAndOpenContract(harness.get(CONTRACT_ID)))
                .clickDocuments()
                .selectDraftDocument(DocumentTemplate.DEPOSIT_PROPOSAL.getName())
                .selectDraftDocument(DocumentTemplate.PLEDGE_AGREEMENT.getName())
                .then(tasks.contractTasks().deleteSelectedDocument());
    }
}