package cz.moneta.test.regression.transactional.cards.retail.creditcard.finishing;

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.search.SearchBy;
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.cards.credit.HPO019_S001_CreditCardDetailPage.CONTRACT_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.operations.client.NewProductsByNameUfoOps.CREDIT_CARD;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo;
import static cz.moneta.test.harness.annotations.Environment.TST1;
import static cz.moneta.test.harness.annotations.Environment.TST3;

@TestScenario(name = "ONB.RET.CC.28 - Retail CC - Application finishing (MoneyCard Smart) (from CallCenter) - BRANCH")
public class Client_fromCallCenter_toBranch {

    NonClient nonClient;

    @BeforeEach
    void setUp(Harness harness, @Key(ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withNetMonthlyIncome(70000)
                .withHomeIncome(70000)
                .withOtherExpenses(10000)
                .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));
    }

    @JiraTestCase(id = "FVP-T78")
    @TestCase(name = "Retail Customer wants to get his MoneyCard Smart on Moneta CallCenter and he will complete origination process on BRANCH", environments = {TST3, TST1})
    public void Retail_CC_Application_Origination_MoneyCard_Smart_BRANCH(Harness harness, @Key(ufo.banka.banker) Credentials credentials) {

        String requestedAmount = "30000";
        String cardName = "MONEYCARD SMART";

        String dailyPurchaseLimit = "30000";
        String dailyWithdrawLimit = "30000";
        String dailyOnlinePaymentsLimit = "30000";

        harness.withUfo()
                .openLoginPage()
                .then(harness.tasks().ufo().operations().login().withCredentialsExpectingError(credentials))
                .dismissErrorPage()
                .fillSearchInput(harness.get(CLIENT_CIF_STORE_KEY))
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .then(harness.tasks().ufo().operations().clientDetails().createNewProductByName(CREDIT_CARD))
                .clickContinue()
                .onCreditCardScoring()
                .assertScoringResultIs("OK")
                .continueToProductSelection()
                .then(harness.tasks().ufo().operations().productActivation().createCreditCardWithDiscountPackage(
                        nonClient,
                        cardName,
                        "KARTA - KARTA",
                        "MC Standard",
                        "Bez akce",
                        requestedAmount,
                        "Na dobu neurčitou",
                        dailyPurchaseLimit,
                        dailyWithdrawLimit,
                        dailyOnlinePaymentsLimit,
                        "bene+ (více na www.beneplus.cz)",
                        "Cestování a sport",
                        "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"
                ))
                .openApplicationList()
                .assertFirstApplicationState("SOUHLAS")
                .assertFirstApplicationRequestedAmount(requestedAmount)
                .assertFirstApplicationApprovedAmount(requestedAmount)
                .clickLogout();

        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()
                .openProductDetail(cardName)
                .onCreditCardDetailPage()
                .storeContractNumber()
                .assertPaymentMethod("Inkasem z účtu");

        harness.withGreenScreen()
                .logIn()
                .openCustomerSearch()
                .searchByIdentificationNumber(nonClient.birthNumber())
                .openCustomerDetail()
                .openAccountDetail()
                .checkOrg("861")
                .checkCardLogo("670")
                .checkName(nonClient.firstName().toUpperCase() + " " + nonClient.lastName().toUpperCase())
                .checkCardholderFlag("0")
                .checkCardAction("1");


        harness.tasks()
                .wso2().cards()
                .getCreditCardInfo(harness.get(CONTRACT_NUMBER_KEY))
                .andAssertFieldValue("RS_3.rows.row.CARD_VARIANT", "1")
                .andAssertFieldValue("RS_3.rows.row.ACC_STAT", "1");
    }
}
