package cz.moneta.test.sanity.transactional.cards.onboarding;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.main.codelists.HCisProductClass;
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.dsl.util.task.firstvision.FirstVisionTasks;
import cz.moneta.test.harness.annotations.Environment;
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.Disabled;

import java.time.LocalDate;

import static cz.moneta.test.dsl.greenscreen.AZXI.AZXI01_CustomerViewSelectScreen.CARD_NUMBER_KEY;
import static cz.moneta.test.dsl.ufo.banka.tasks.accountenums.DebitCardFeePlan.CHARGED;
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.HKO101_S001_MainClientPage.CURRENT_ACCOUNT_NUMBER;

@TestScenario(name = "Create customer, debit card")
public class RetailDCVisaStandard {

    private NonClient nonClient;

    private void setUp(Harness harness, Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withNetMonthlyIncome(100000)
                .withHomeIncome(100000)
                .withOtherExpenses(5000)
                .withOtherLoanPayments(0);
        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))
                .getCurrentAccountNumberAndStore();
    }

    //name = "ONB.RET.DC.01 - Retail DC - Card Onboarding (Debit VISA Standard) - BRANCH. Banker creates Debit card (Debit VISA Standard) for an existing client with existing account"
    @Disabled
    @JiraTestCase(id = "FVP-T2763")
    @TestCase(name = "retail_DC_VISA_Standard_onboarding", environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    public void createRetailDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        setUp(harness, credentials);
        final String cardName = "Debit VISA Standard (FV)";
        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .fillSearchTerm(harness.get(CLIENT_CIF_STORE_KEY))
                .clickSearchByCif()
                .onClientDetailPage()
                .getCurrentAccountNumberAndStore()
                .createNewProduct(HCisProductClass.DEBIT_CARD)
                .onSelectionOfSubmittedDocumentsPage()
                .selectIdCardRadio()
                .clickDocumentsCheckButton()
                .clickContinue()
                .onDebitCardRequestPage()
                .selectCurrentAccountByIndex(2)
                .selectDebitCardType(cardName + "|Nabízet")
                .selectDebitCardFeePlan(CHARGED)
                .typeActivatePassword("000000")
                .clickClientDataHolderButton()
                .clickEnterButton()
                .onAddHolderPage()
                .clickOnHolderOwnerButton()
                .clickCardDeliveryToPermanentAddress()
                .clickPinDeliveryToPermanentAddress()
                .dismissPinChargeAlert()
                .waitForLoadAndClickSend()
                .onSignerSelectionPage()
                .clickContinue()
                .onPrintDocumentationPage()
                .continueToGeneralContractAndDispositionPage()
                .continueToSummaryPage()
                .checkTextLabelContent("Debetní karta byla úspěšně založena")
                .clickOk()
                .onMainClientPage();

        String accountNumber = harness.get(CURRENT_ACCOUNT_NUMBER);
        FirstVisionTasks fv = harness.tasks().firstVision();
        fv.updateExpirationDate(accountNumber, LocalDate.parse("2023-10-10"));
        harness.tasks().wso2().cards().activateCard(harness.get(CARD_NUMBER_KEY));
        harness.store("reports.tmfj.execution.comment", "Card successfully created, client "
                + nonClient.firstName() + " " + nonClient.lastName()
                + " (" + nonClient.birthNumber() + ")");
    }
}
