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 = "Create Accident Insurance on the client in UFO Banka ")
public class AccidentInsuranceUfo {

    private String birthNumber;
    private String cifNumber;

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

    @Order(1)
    @TestCase(name = "Log on UFO BANKA and new accident insurance family", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T343")
    void arrangementAccidentInsuranceFamily(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Úrazové pojištění - varianta Rodina";
        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 accident insurance for adults ", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T344")
    void arrangementInsuranceAccidentInsuranceForAdults(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Úrazové pojištění - varianta Dospělý";
        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 accident insurance junior", environments = {TST1, PPE})
    @JiraTestCase(id = "INS-T345")
    void arrangementInsuranceJunior(Harness harness, @Key(Keys.ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Úrazové pojištění - varianta Junior - rodičovský";
        String rcJunior = harness.tasks().common().getRcByMaxAge(7);
        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))
                .fillRc(rcJunior)
                .fillGivenName("Junior")
                .fillFamilyName("Pojisteny")
                .clickCheckBox()
                .then(tasks.newInsuranceGroupTasks().completeAndCheckActiveInsurance(productName));
    }
}