package cz.moneta.test.regression.feeincome.ib;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@Execution(ExecutionMode.SAME_THREAD)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestScenario(name = "Verify Long Term Travel Insurance")
public class LongTermTravelInsuranceIb {

    private String birthNumber;

    @BeforeEach
    void cancelInsurance(Harness harness) {
        birthNumber = harness.getConfig("rc.longTermTravelInsuranceIb");
        harness.tasks()
                .insuranceTasks()
                .setInsuranceStatusTask()
                .cancelInsurance(birthNumber);
    }

    @Order(1)
    @TestCase(name = "Go to insurance page and create LongTerm Travell Insurance", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T331")
    void createLongTermTravelInsuranceEuropaFamilyIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateLongTermInsurance()
                .clickAccountSelect()
                .clickRegionEuropeSelect()
                .clickVariantFamilySelect()
                .then(harness.tasks().ib().insuranceIbTasks().createLongTermTravelInsuranceWithDefaultMobileKey())
                .checkLongTravelEuropeFamilyInsuranceIsFound();
    }

    @Order(2)
    @TestCase(name = "Go to insurance page and create LongTerm Travell Insurance", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T332")
    void createLongTermTravelInsuranceEuropaSingleIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateLongTermInsurance()
                .clickAccountSelect()
                .clickRegionEuropeSelect()
                .clickVariantSingleSelect()
                .then(harness.tasks().ib().insuranceIbTasks().createLongTermTravelInsuranceWithDefaultMobileKey())
                .checkLongTravelEuropeSingleInsuranceIsFound();
    }

    @Order(3)
    @TestCase(name = "Go to insurance page and create LongTerm Travell Insurance", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T333")
    void createLongTermTravelInsuranceWorldFamilyIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateLongTermInsurance()
                .clickAccountSelect()
                .clickRegionWorldSelect()
                .clickVariantFamilySelect()
                .then(harness.tasks().ib().insuranceIbTasks().createLongTermTravelInsuranceWithDefaultMobileKey())
                .checkLongTravelWorldFamilyInsuranceIsFound();
    }

    @Order(4)
    @TestCase(name = "Go to insurance page and create LongTerm Travell Insurance", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T334")
    void createLongTermTravelInsuranceWorldSingleIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateLongTermInsurance()
                .clickAccountSelect()
                .clickRegionWorldSelect()
                .clickVariantSingleSelect()
                .then(harness.tasks().ib().insuranceIbTasks().createLongTermTravelInsuranceWithDefaultMobileKey())
                .checkLongTravelWorldSingleInsuranceIsFound();
    }
}