package cz.moneta.test.regression.collateral.hypos;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.hypos.contractPrepare.HyposContractPrepare;
import cz.moneta.test.dsl.hypos.enums.HyposProfile;
import cz.moneta.test.dsl.hypos.tasks.HyposTasks;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import org.junit.jupiter.api.BeforeEach;

@TestScenario(name = "Tests in Hypos")
public class MarketValuationForm {

    private HyposTasks tasks;
    private static String contractId;
    final static int REALTY_FLAT_VERIFICATION = 0;

    @BeforeEach
    public void setup(Harness harness) {
        HyposContractPrepare contractPrepare = new HyposContractPrepare(harness);
        contractId = contractPrepare.createNewContract(harness);
        contractPrepare.createNewContract(harness);
        contractPrepare.closeBrowser();
        contractPrepare.addUnitToRealty(harness, contractId, REALTY_FLAT_VERIFICATION);
        contractPrepare.closeBrowser();
        contractPrepare.createValuationFlat(harness, contractId);
        contractPrepare.closeBrowser();
    }

    //TODO add tests for disappearing values after refresh
    @TestCase(name = "Check elements presence, correctness of calculations and disappearing values after refresh.")
    public void checkFlatValuationForm(Harness harness){
        tasks = harness.tasks().hypos();
        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.SUPERVISOR))
                .then(tasks.searchAndOpenContract(contractId))
                .clickRealty()
                .clickRealtyDetail()
                .openFirstOrder()
                .checkSharedElements()
                .then(tasks.valuationTasks().checkFlatElements())
                .then(tasks.valuationTasks().verifyReproductivePrice())
                ;
    }

    @TestCase(name = "Tests all possible operations with order with check in operations history.")
    public void orderOperations(Harness harness) {
        tasks = harness.tasks().hypos();
        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.SUPERVISOR))
                .then(tasks.searchAndOpenContract(contractId))
                .clickRealty()
                .clickRealtyDetail()
                .openFirstOrder()
                .then(tasks.valuationTasks().giveOrder())
                .then(tasks.valuationTasks().takeOrder())
                .then(tasks.valuationTasks().deferOrder())
                .then(tasks.valuationTasks().cancelOrder())
        ;
    }

    @TestCase(name = "Finish order test with verification about successful result.")
    public void finishOrder(Harness harness) {
        tasks = harness.tasks().hypos();
        harness.withHypos()
                .openLoginPage()
                .then(tasks.loginToHyposWithProfile(HyposProfile.SUPERVISOR))
                .then(tasks.searchAndOpenContract(contractId))
                .clickRealty()
                .clickRealtyDetail()
                .openFirstOrder()
                .then(tasks.valuationTasks().finishOrder())
        ;
    }
}
