package cz.moneta.test.regression.channels.digital.ib.oldib.insurance;

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.*;
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")
public class AccidentInsuranceTest {

    private String birthNumber;

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

    @Disabled
    @Order(1)
    @TestCase(name = "Go to insurance page and create accident insurance - variant junior", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8358")
    void userWithCurrentAccount_shouldCreateAccidentInsuranceJunior(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().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickInsurance()
                .clickCreateAccidentInsurence()
                .clickAccountSelect()
                .clickInsuranceSelectJunior()
                .fillToFirstName("Jan")
                .fillToLastName("Novák")
                .fillToIdentificationNumberName(harness.data().newNonClient().birthNumber(bornFrom, bornTo))
                .clickChildrenAgreement()
                .clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode("12341234")
                .clickSend()
                .clickListInsurace()
                .checkInsuranceIsFound("Úrazové pojištění - varianta Junior");
    }

    @Disabled
    @Order(2)
    @TestCase(name = "Go to insurance page and create accident insurance - variant adult", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8359")
    void userWithCurrentAccount_shouldCreateAccidentInsuranceAdult(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickInsurance()
                .clickCreateAccidentInsurence()
                .clickAccountSelect()
                .clickInsuranceSelectAdult()
                .clickInvalidityAgreement()
                .clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode("12341234")
                .clickSend()
                .clickListInsurace()
                .checkInsuranceIsFound("Úrazové pojištění - varianta Dospělý");
    }

    @Disabled
    @Order(3)
    @TestCase(name = "Go to insurance page and create accident insurance - variant family", environments = {TST1, PPE})
    @JiraTestCase(id = "IB-T8360")
    void userWithCurrentAccount_shouldCreateAccidentInsuranceFamily(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().loginWithDefaultMobileKeyAnd(udebsCredentials))
                .clickInsurance()
                .clickCreateAccidentInsurence()
                .clickAccountSelect()
                .clickInsuranceSelectFamily()
                .clickInvalidityAgreement()
                .clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode("12341234")
                .clickSend()
                .clickListInsurace()
                .checkInsuranceIsFound("Úrazové pojištění - varianta Family");
    }
}
