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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.task.brokerportal.BrokerPortalPreconditions;
import cz.moneta.test.dsl.util.task.brokerportal.BrokerPortalTasks;
import cz.moneta.test.harness.annotations.ParameterizedTestCase;
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.BeforeEach;
import org.junit.jupiter.params.provider.ValueSource;

@TestScenario(name = "Prepare data for valuation testing")
public class AllValuations {

    private final static int VERIFIKACE_FLAT = 0;
    private final static int DESKTOP_FLAT = 1;
    private final static int FULL_FLAT = 2;
    private final static int ONLINE_FLAT = 3;

    private final static int DESKTOP_HOUSE = 0;
    private final static int FULL_HOUSE = 1;

    private static String contractId;

    @BeforeEach
    public void setup(Harness harness, @Key(Keys.brokerPortal.broker) Credentials broker) {
        BrokerPortalPreconditions bpPreconditions = new BrokerPortalPreconditions(harness, broker);
        contractId = bpPreconditions.createNewContract();
        bpPreconditions.closeBrowser();
    }

    @ParameterizedTestCase(name = "Broker portal valuations for flats.")
    @ValueSource(ints = {VERIFIKACE_FLAT, DESKTOP_FLAT, FULL_FLAT, ONLINE_FLAT})
    public void flatValuations(int valuationType, Harness harness, @Key(Keys.brokerPortal.broker) Credentials broker) {
        BrokerPortalTasks tasks = harness.tasks().brokerPortal();
        harness.withBrokerPortal().openLoginPage()
                .then(tasks.loginTasks().loginWithCredentials(broker))
                .then(tasks.brokerPortalValuations().findContract(contractId))
                .then(tasks.brokerPortalValuations().evaluateFlat(valuationType, contractId))
        ;

    }
    @ParameterizedTestCase(name = "Broker portal valuations for houses.")
    @ValueSource(ints = {DESKTOP_HOUSE, FULL_HOUSE})
    public void houseValuations(int valuationType, Harness harness, @Key(Keys.brokerPortal.broker) Credentials broker) {
        BrokerPortalTasks tasks = harness.tasks().brokerPortal();
        harness.withBrokerPortal().openLoginPage()
                .then(tasks.loginTasks().loginWithCredentials(broker))
                .then(tasks.brokerPortalValuations().findContract(contractId))
                .then(tasks.brokerPortalValuations().evaluateHouse(valuationType, contractId));
    }
}
