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

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.TestUtils;
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.greenscreen.AZXI.AZXI01_CustomerViewSelectScreen.CARD_NUMBER_KEY;
import static cz.moneta.test.dsl.ufo.banka.tasks.accountenums.DebitCardFeePlan.FREE;
import static cz.moneta.test.dsl.ufo.banka.pages.main.BAL001_S008_SummaryStartDocumentsPage.ACCOUNT_NUMBER_KEY;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo;
import static cz.moneta.test.harness.annotations.Environment.TST3;

@TestScenario(name = "ONB.PM.RET.DC.07 - DC - Retail - Card Onboarding - Debit VISA GOLD with existing Tom - BRANCH")
public class Client_fromBranch_toBranch_TOM_VISA_Gold {

    NonClient nonClient;

    @BeforeEach
    void setUp(Harness harness, @Key(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.newProduct().createNewCurrentAccount(CurrentAccountsEnum.TOM))
                .then(bankaTasks.newProduct().ibWithMobileKey(nonClient));
    }

    @JiraTestCase(id = "FVP-T388") // DISP.RET.DC53
    @JiraTestCase(id = "FVP-T1182")
    @TestCase(name = "Banker creates for a retail client Debit card Visa GOLD. Bank account Tom exists", environments = {TST3})
    public void tc1(Harness harness, @Key(ufo.banka.banker) Credentials credentials) {

        final String cardName = "Debit VISA Gold (FV)";

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .fillSearchTerm(nonClient.birthNumber())
                .clickSearchByRc()
                .onClientDetailPage()
                .then(bankaTasks.newProduct().createNewDebitCardForExistingCurrentAccount(cardName, FREE))
                .then(bankaTasks.newProduct().verifyDebitCardDetails(
                        nonClient,
                        cardName,
                        "Zpoplatněná",
                        "Expirovaná",
                        "30 000",
                        "100 000",
                        "0",
                        "000000"
                ))
                .then(bankaTasks.newProduct().verifyCurrentAccountDetails(
                        "Tom účet",
                        "-200,00",
                        "CZK",
                        "BÚ-FO- KONTO GENIUS /R/",
                        TestUtils.getTodayDate(),
                        "Tom účet"
                ));

        String accountNumber = harness.get(ACCOUNT_NUMBER_KEY);
        harness.tasks().firstVision().verifyDebitCard(
                nonClient,
                accountNumber,
                "860",
                "151",
                "A"
        );

        String cardNumber = harness.get(CARD_NUMBER_KEY);
        harness.tasks()
                .wso2().cards()
                .getDebitCardInfo(accountNumber)
                .andAssertFieldValue("RS_3.rows.row.CARD_NUM", cardNumber)
                .andAssertFieldValue("RS_3.rows.row.RC_NUM_HOLDER", nonClient.birthNumber())
                .andAssertFieldValue("RS_3.rows.row.ACC_STAT", "1");

        // TODO: Add ICBS Check
    }
}
