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 static cz.moneta.test.dsl.ufo.banka.pages.main.BAL001_S008_SummaryStartDocumentsPage.ACCOUNT_NUMBER_KEY;
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 = "New Insurance Of Payments And Expenses")
public class NewInsuranceOfPaymentsAndExpenses {

    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 new insurance of payments and expenses")
    @JiraTestCase(id = "INS-T352")
    void arrangementInsuranceOfPaymentsAndExpenses(Harness harness, @Key(ufo.banka.banker) Credentials ufoBanker) {
        String productName = "Pojištění splátek a výdajů";
        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)
                .selectAccount(harness.get(ACCOUNT_NUMBER_KEY))
                .clickContinue()
                .onSignerSelectionPage()
                .chooseCitizen()
                .clickContinue()
                .onVerificationOfSignaturePage()
                .clickSignedButtonAndContinueToEnterIntoOtherInsurancePage()
                .clickFinishButtonAndContinueToPrintDispositionsPage()
                .clickPostponePrintButtonAndContinueToProductsListPage()
                .clickClientAgreedAndSignedAll()
                .clickContinue()
                .onMainClientPage()
                .checkProductActive(productName);
    }
}
