package cz.moneta.test.regression.commercial.auto.smartauto;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.auto.smartauto.shared.*;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.task.auto.smartauto.SmartAutoTasks;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import cz.moneta.test.regression.commercial.auto.smartauto.mockdata.*;
import org.junit.jupiter.api.BeforeEach;

public abstract class AbstractTest {

    protected Harness harness;
    protected Credentials generalCredentials;

    @BeforeEach
    public void init(Harness harness, @Key(Keys.smart.auto.general) Credentials credentials) {
        this.harness = harness;
        generalCredentials = credentials;
    }

    protected final void motorcycleTasks(CalculationData calculationData) {
        SmartAutoTasks smartAutoTasks = harness.tasks().auto().smartAuto();
        CompanyData companyData = SharedMock.prepareCompanyData();
        ContactData contactData = SharedMock.prepareContactDataMan();
        IdentificationData identificationData = SharedMock.prepareIdentificationDataMan();

        harness.withSmartAuto()
                .openLoginPage()
                .then(smartAutoTasks.login().loginWithCredentials(generalCredentials))
                .then(smartAutoTasks.calculationType().makeCalculation(calculationData))
                .then(smartAutoTasks.insuranceTasks().fillCustomerData(calculationData, smartAutoTasks, contactData, identificationData, companyData))
                .then(smartAutoTasks.insuranceTasks().fillInsuranceData(calculationData, smartAutoTasks))
                .then(smartAutoTasks.calculationType().closeInsuranceModal())
                .then(smartAutoTasks.verification().checkNewCalculation());

    }

    protected final void sharedTasks(CalculationData calculationData) {
        SmartAutoTasks smartAutoTasks = harness.tasks().auto().smartAuto();
        CompanyData companyData = SharedMock.prepareCompanyData();
        ContactData contactData = SharedMock.prepareContactDataMan();
        IdentificationData identificationData = SharedMock.prepareIdentificationDataMan();

        harness.withSmartAuto()
                .openLoginPage()
                .then(smartAutoTasks.login().loginWithCredentials(generalCredentials))
                .then(smartAutoTasks.calculationType().makeCalculation(calculationData))
                .then(smartAutoTasks.insuranceTasks().fillCustomerData(calculationData, smartAutoTasks, contactData, identificationData, companyData))
                .then(smartAutoTasks.insuranceTasks().fillInsuranceData(calculationData, smartAutoTasks))
                .then(smartAutoTasks.calculationType().closeInsuranceModal())
                .then(smartAutoTasks.verification().checkNewCalculation());
    }

    protected final void trailerTasks(CalculationData calculationData) {
        SmartAutoTasks smartAutoTasks = harness.tasks().auto().smartAuto();
        CompanyData companyData = SharedMock.prepareCompanyData();
        ContactData contactData = SharedMock.prepareContactDataMan();
        IdentificationData identificationData = SharedMock.prepareIdentificationDataMan();

        harness.withSmartAuto()
                .openLoginPage()
                .then(smartAutoTasks.login().loginWithCredentials(generalCredentials))
                .then(smartAutoTasks.calculationType().makeCalculation(calculationData))
                .then(smartAutoTasks.insuranceTasks().fillCustomerData(calculationData, smartAutoTasks, contactData, identificationData, companyData))
                .then(smartAutoTasks.insuranceTasks().fillInsuranceData(calculationData, smartAutoTasks))
                .then(smartAutoTasks.calculationType().closeInsuranceModal())
                .then(smartAutoTasks.verification().checkNewCalculation());
    }

    protected final void agroTpTasks(CalculationData calculationData) {
        SmartAutoTasks smartAutoTasks = harness.tasks().auto().smartAuto();
        CompanyData companyData = SharedMock.prepareCompanyData();

        harness.withSmartAuto()
                .openLoginPage()
                .then(smartAutoTasks.login().loginWithCredentials(generalCredentials))
                .then(smartAutoTasks.calculationType().makeCalculationAgro(calculationData))
                .then(smartAutoTasks.insuranceTasks().fillCustomerData(calculationData, smartAutoTasks, companyData))
                .then(smartAutoTasks.insuranceTasks().fillInsuranceData(calculationData, smartAutoTasks))
                .then(smartAutoTasks.calculationType().closeInsuranceModal())
                .then(smartAutoTasks.verification().checkNewCalculation());
    }


}
