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;

@Execution(ExecutionMode.SAME_THREAD)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@TestScenario(name = "Verify Insurance for Paymants, Cards, Expenses and Risks")
public class PaymentsCardsExpensesRiskInsurance {

    private String birthNumber;
    private final String SMS_CODE = "12341234";

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

    @Order(1)
    @TestCase(name = "Go to insurance page and create Electronic Paymants Insurance")
    @JiraTestCase(id = "INS-T330")
    void createElectronicPaymantsInsuranceIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateElectronicPaymentInsurance()
                .clickAccountSelect()
                .clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode(SMS_CODE)
                .clickSend()
                .clickListInsurace()
                .checkElectronicPaymentInsuranceIsFound();
    }

    @Order(2)
    @TestCase(name = "Go to insurance page and create Payments and Expense Insurance")
    @JiraTestCase(id = "INS-T338")
    void createPaymentsAndExpensesInsuranceIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreatePaymentsAndExpensesInsurance()
                .clickAccountSelect()
                .clickHealthCOnditionConfirmation()
                .clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode(SMS_CODE)
                .clickSend()
                .clickListInsurace()
                .checkPaymentsAndExpensesInsuranceIsFound();
    }

    @Order(3)
    @TestCase(name = "Go to insurance page and create Electronic Paymants Insurance")
    @JiraTestCase(id = "INS-T339")
    void createPropertyCardsAndInternetRisksInsuranceIb(Harness harness) {
        Credentials udebsCredentials = harness.tasks().udebs().findCredentialsByRC(birthNumber);

        harness.withIB()
                .openLoginPage()
                .then(harness.tasks().ib().insuranceIbTasks().loginWithDefaultMobileKeyAndClickInsurance(udebsCredentials))
                .clickCreateInsuranceOfPropertyCardsAndInternetRisks()
                .clickAccountSelect()
                .clickLicenceAgreement()
                .clickInsuranceAgreement()
                .clickContinueButton()
                .typeSmsCode(SMS_CODE)
                .clickSend()
                .clickListInsurace()
                .checkPropertyCardsAndInternetRiskInsuranceIsFound();
    }
}