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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CardBrand;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.NeedInsurance;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.ProductType;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
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.BeforeEach;

import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CreditCardsAdvantages.ELECTRONICS;
import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CreditCardsPromo.NO_PROMO;
import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.HPO019_S001_CreditCardDetailPage.CONTRACT_NUMBER_KEY;

@TestScenario(name = "ONB.PM.RET.CC.30 - CC - Retail - Card Onboarding - MONEYCARD VISA SMART with existing Tom - BRANCH")
public class Client_fromBranch_toBranch_Tom_VisaSmart {

    NonClient nonClient;

    @BeforeEach
    void setUp(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withNetMonthlyIncome(100000)
                .withHomeIncome(100000)
                .withOtherExpenses(5000)
                .withOtherLoanPayments(0);

        nonClient.withBirthNumber("7204016083");

//        BankaTasks bankaTasks = harness.tasks().ufo().banka();
//        harness.withUfo()
//                .openLoginPage()
//                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
//                .then(bankaTasks.newClient().create(nonClient))
//                .then(bankaTasks.newPackagedProductTasks().ibWithMobileKeyAndCurrentAccount(CurrentAccountsEnum.GENIUS_FREE_FLEXI));
    }

    @JiraTestCase(id = "FVP-T1206")
    @TestCase(name = "Banker creates for a retail client Credit card MONEYCARD VISA SMART. Bank account Tom exists", environments = {Environment.TST3})
    public void Retail_CC_Application_Origination_MoneyCard_Smart_BRANCH(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        String requestedAmount = "30000";
        String cardName = "MONEYCARD SMART";

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .fillSearchTerm(nonClient.birthNumber())
                .clickSearchByRc()
                .onClientDetailPage()
                .then(bankaTasks.newProduct().createNewCreditCard(
                        nonClient,
                        ProductType.MONEYCARD_SMART,
                        NeedInsurance.NO,
                        CardBrand.VISA,
                        ELECTRONICS,
                        NO_PROMO,
                        requestedAmount,
                        "30000",
                        "100000",
                        "100000"))
                .then(bankaTasks.newProduct().verifyCreditCardDetails(
                        cardName));

        harness.tasks().firstVision().verifyCreditCard(
                nonClient,
                "861",
                "670",
                "0",
                "1"
        );

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