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 Short Term Travel Insurance")
public class ShortTermTravelInsurance {

    private String birthNumber;

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

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

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateShortTermInsurance()
                .clickAccountSelect()
                .clickRegionEuropeSelect()
                .clickVariantFamilySelect()
                .then(harness.tasks().ib().insuranceIbTasks().createShortTermTravelInsuranceWithDefaultMobileKey())
                .checkShortTravelEuropeFamilyInsuranceIsFound();
    }

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

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateShortTermInsurance()
                .clickAccountSelect()
                .clickRegionEuropeSelect()
                .clickVariantSingleSelect()
                .then(harness.tasks().ib().insuranceIbTasks().createShortTermTravelInsuranceWithDefaultMobileKey())
                .checkShortTravelEuropeSingleInsuranceIsFound();
    }

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

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateShortTermInsurance()
                .clickAccountSelect()
                .clickRegionWorldSelect()
                .clickVariantFamilySelect()
                .then(harness.tasks().ib().insuranceIbTasks().createShortTermTravelInsuranceWithDefaultMobileKey())
                .checkShortTravelWorldFamilyInsuranceIsFound();
    }

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

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateShortTermInsurance()
                .clickAccountSelect()
                .clickRegionWorldSelect()
                .clickVariantSingleSelect()
                .then(harness.tasks().ib().insuranceIbTasks().createShortTermTravelInsuranceWithDefaultMobileKey())
                .checkShortTravelWorldSingleInsuranceIsFound();
    }
}