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.ufo.banka.tasks.accountenums.CurrentAccountsEnum;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
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 java.time.LocalDate;

import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.CLIENT_CIF_STORE_KEY;
import static cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass.INSURANCE;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo;

@TestScenario(name = "Short Term Travel Insurance Europe Single")
public class ShortTermTravelInsuranceEuropeSingle {

    private NonClient nonClient;

    @BeforeEach
    void setUp(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newNonClient();
        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.newClient().create(nonClient, credentials.getUsername()))
                .then(bankaTasks.newPackagedProductTasks().ibWithMobileKeyAndCurrentAccount(nonClient, CurrentAccountsEnum.GENIUS_FREE_FLEXI));
    }

    @TestCase(name = "Log on UFO BANKA and arrangement new short term travel insurance europe single ")
    @JiraTestCase(id = "INS-T355")
    void arrangementShortTermTravelInsuranceEuropeSingle(Harness harness, @Key(ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Krátkodobé cestovní pojištění Evropa (single)";
        String rc = nonClient.birthNumber();
        String account = harness.withUdebs().accountNumbers().getTopCurrentAccount(rc).substring(1);
        BankaTasks tasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(tasks.login().withCredentialsAndTurnOffSignpad(ufoBanker))
                .fillSearchTerm(harness.get(CLIENT_CIF_STORE_KEY))
                .clickSearchByCif()
                .onClientDetailPage()
                .createNewProduct(INSURANCE)
                .onInsuranceSelectPage()
                .clickGroupInsuranceButtonAndContinueToChooseInsurancePage()
                .selectInsurance(productName)
                .waitUntilLoaderIsGone()
                .selectAccount(account)
                .waitUntilLoaderIsGone()
                .fillDateFrom(LocalDate.now().plusDays(1))
                .fillDateUntil(LocalDate.now().plusDays(3))
                .waitUntilPriceIsCalculated()
                .clickContinue()
                .onSignerSelectionPage()
                .clickContinue()
                .onVerificationOfSignaturePage()
                .clickSignedButtonAndContinueToEnterIntoOtherInsurancePage()
                .clickFinishButtonAndContinueToDispositionsPage()
                .clickGenerateNow()
                .onContractDocumentationPage()
                .clickContinue()
                .onSummaryStartDocumentsPage()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(productName);
    }


}

