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 java.time.LocalDate;

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 Accident Insurance in Internet Banka")
public class AccidentInsuranceIb {

    private String birthNumber;

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

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

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateAccidentInsurence()
                .clickAccountSelect()
                .clickInsuranceSelectFamily()
                .clickInvalidityAgreement()
                .then(harness.tasks().ib().insuranceIbTasks().createAccidentInsuranceWithDefaultMobileKey())
                .checkAccidentFamilyInsuranceIsFound();
    }

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

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateAccidentInsurence()
                .clickAccountSelect()
                .clickInsuranceSelectAdult()
                .clickInvalidityAgreement()
                .then(harness.tasks().ib().insuranceIbTasks().createAccidentInsuranceWithDefaultMobileKey())
                .checkAccidentAdultInsuranceIsFound();
    }

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

        LocalDate bornFrom = LocalDate.now().minusYears(14);
        LocalDate bornTo = LocalDate.now();

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateAccidentInsurence()
                .clickAccountSelect()
                .clickInsuranceSelectJunior()
                .fillToFirstName("Petr")
                .fillToLastName("Svetr")
                .fillToIdentificationNumberName(harness.data().newNonClient().birthNumber(bornFrom, bornTo))
                .clickChildrenAgreement()
                .then(harness.tasks().ib().insuranceIbTasks().createAccidentInsuranceWithDefaultMobileKey())
                .checkAccidentJuniorInsuranceIsFound();
    }
}