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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
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 cz.moneta.test.harness.support.auth.Key;
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 = "New Long Term Travel Insurance 2019")
public class LongTermTravelInsurance {

    private String birthNumber;
    private String cifNumber;

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

    @Order(1)
    @TestCase(name = "Log on UFO BANKA and new Long Term Travel Insurance Europe Family", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T347")
    void createLongTermTravelEuropeFamilyInsuranceUfo(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Dlouhodobé cestovní pojištění Evropa 2019 (family)";
        String account = harness.withUdebs().accountNumbers().getTopCurrentAccount(birthNumber).substring(1);
        BankaTasks tasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(tasks.login().withCredentialsAndTurnOffSignpad(ufoBanker))
                .then(tasks.newInsuranceGroupTasks().findCifAndCreateGroupInsuranceProduct(cifNumber, productName, account))
                .then(tasks.newInsuranceGroupTasks().completeAndCheckActiveInsurance(productName));
    }

    @Order(2)
    @TestCase(name = "Log on UFO BANKA and new Long Term Travel Insurance Europe Single", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T348")
    void createLongTermTravelEuropeSingleInsuranceUfo(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Dlouhodobé cestovní pojištění Evropa 2019 (single)";
        String account = harness.withUdebs().accountNumbers().getTopCurrentAccount(birthNumber).substring(1);
        BankaTasks tasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(tasks.login().withCredentialsAndTurnOffSignpad(ufoBanker))
                .then(tasks.newInsuranceGroupTasks().findCifAndCreateGroupInsuranceProduct(cifNumber, productName, account))
                .then(tasks.newInsuranceGroupTasks().completeAndCheckActiveInsurance(productName));
    }

    @Order(3)
    @TestCase(name = "Log on UFO BANKA and new Long Term Travel Insurance World Family", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T349")
    void createLongTermTravelWorldFamilyInsuranceUfo(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Dlouhodobé cestovní pojištění Svět 2019 (family)";
        String account = harness.withUdebs().accountNumbers().getTopCurrentAccount(birthNumber).substring(1);
        BankaTasks tasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(tasks.login().withCredentialsAndTurnOffSignpad(ufoBanker))
                .then(tasks.newInsuranceGroupTasks().findCifAndCreateGroupInsuranceProduct(cifNumber, productName, account))
                .then(tasks.newInsuranceGroupTasks().completeAndCheckActiveInsurance(productName));
    }

    @Order(4)
    @TestCase(name = "Log on UFO BANKA and new Long Term Travel Insurance World Single", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T351")
    void createLongTermTravelWorldSingleInsuranceUfo(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Dlouhodobé cestovní pojištění Svět 2019 (single)";
        String account = harness.withUdebs().accountNumbers().getTopCurrentAccount(birthNumber).substring(1);
        BankaTasks tasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(tasks.login().withCredentialsAndTurnOffSignpad(ufoBanker))
                .then(tasks.newInsuranceGroupTasks().findCifAndCreateGroupInsuranceProduct(cifNumber, productName, account))
                .then(tasks.newInsuranceGroupTasks().completeAndCheckActiveInsurance(productName));
    }
}