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

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.ufo.operations.client.NewProductsByNameUfoOps;
import cz.moneta.test.dsl.ufo.operations.search.SearchBy;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.data.client.NonClient;
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.pages.main.HKO101_S001_MainClientPage.CLIENT_CIF_STORE_KEY;

@TestScenario(name = "Create customer, credit card")
public class RetailCCMoneyCardGold {
    private NonClient nonClient;

    private void setUp(Harness harness, @Key(Keys.ufo.banka.banker) 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));
    }

    //ONB.RET.CC.08 - Retail CC - Application Origination - MoneyCard Gold - CC
    @Disabled
    @JiraTestCase(id = "FVP-T2750")
    @TestCase(name = "Retail CC - MoneyCard Gold", environments = {Environment.TST3, Environment.FVE, Environment.PPE})
    public void createRetailCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        setUp(harness, credentials);
        String requestedAmount = "40000";
        String cardName = "MoneyCard Gold";

        String dailyPurchaseLimit = "40000";
        String dailyWithdrawLimit = "40000";
        String dailyOnlinePaymentsLimit = "40000";

        harness.withUfo()
                .openLoginPage()
                .then(harness.tasks().ufo().operations().login().withCredentials(credentials))
                .fillSearchInput(harness.get(CLIENT_CIF_STORE_KEY))
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .then(harness.tasks().ufo().operations().clientDetails().createNewProductByName(NewProductsByNameUfoOps.CREDIT_CARD))
                .clickContinue()
                .onCreditCardScoring()
                .assertScoringResultIs("OK")
                .continueToProductSelection()
                .then(harness.tasks().ufo().operations().productActivation().createCreditCard(
                        nonClient,
                        cardName,
                        "KARTA - KARTA",
                        "MC Gold",
                        "Bez akce",
                        requestedAmount,
                        "Na dobu neurčitou",
                        dailyPurchaseLimit,
                        dailyWithdrawLimit,
                        dailyOnlinePaymentsLimit,
                        "bene+ (více na www.beneplus.cz)",
                        "BÚ Genius Free & Flexi",
                        "111111"
                ))
                .checkProduct("Kreditní karta")
                .scheduleMeetingAtABranch()
                .then(harness.tasks().ufo().operations().meetingTasks().scheduleMeeting(
                        "ČESKÉ BUDĚJOVICE - JÍROVCOVA - Jírovcova 1863/1",
                        "Prodej",
                        "Kreditní karta"
                ))
                .menuClickClientApplications()
                .assertFirstApplicationState("SOUHLAS")
                .assertFirstApplicationRequestedAmount(requestedAmount)
                .assertFirstApplicationApprovedAmount(requestedAmount)
                .clickLogout()
                .clickRelogin();
// ONB.RET.CC.28 - Retail CC
        harness.withUfo()
                .openLoginPage()
                .then(harness.tasks().ufo().banka().login().withCredentialsAndTurnOffSignpad(credentials))
                .fillSearchTerm(harness.get(CLIENT_CIF_STORE_KEY))
                .clickSearchByCif()
                .onClientDetailPage()
                .selectFromListOfRequests()
                .selectFirstApplication()
                .clickOpenRequestDetail()
                .onCreditCardRequestPage()
                .clickCreateProductAndPrintContract()
                .onPreContractualInformationPrintedPage()
                .continueToPrintCopyOfContractProposalPage()
                .clickContinue()
                .onCreditCardRepaymentMethodConfirmation()
                .clickOk()
                .onConfirmationPage()
                .clickLeftButton()
                .onAccountSelectionPage()
                .selectAccount(2)
                .clickSave()
                .onConfirmationPage()
                .clickDoNotCreateButton()
                .onSignerSelectionPage()
                .clickContinue()
                .onSignContractPage()
                .clickFirstSignerCheckbox()
                .clickYesButton()
                .clickOk()
                .clickContinue()
                .clickContinue()
                .fillPriceLimitInput(requestedAmount)
                .clickSaveButton()
                .clickSigned()
                .clickContinue()
                .onClientRequestPage()
                .clickBackToMainPage();

        harness.withGreenScreen()
                .logIn()
                .openCustomerSearch()
                .searchByIdentificationNumber(nonClient.birthNumber())
                .openCustomerDetail()

                .openAccountDetail()

                .checkOrg("861")
                .checkCardLogo("680")
                .checkName(nonClient.firstName().toUpperCase() + " " + nonClient.lastName().toUpperCase())
                .checkCardholderFlag("0")
                .checkCardAction("1");

        harness.tasks().firstVision()
                .updateExpirationDateCC(nonClient.birthNumber(), 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() + ")");
    }

}
