package cz.moneta.test.regression.cards.jenkinstests;

import cz.moneta.test.dsl.Harness;
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.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.apache.commons.lang.StringUtils;
import org.junit.jupiter.api.AfterEach;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Teller must be able to change the actual state of Internet/MOTO transactions")
public class ChangeMotoInternetTransactions {

    String reportingId;
    String testCardForJira;

    public void changeMotoIntForStandardDebitCard(Harness harness, Credentials credentials, String birthNumber, String testCard) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withBirthNumber(birthNumber);
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRcWithAlert(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsRetailDebitCard(testCardLastNumbers))
        ;

        reportingId = "Rč klienta " + nonClient.birthNumber();
        testCardForJira = testCard;
    }

    public void changeMotoIntForCommercialDebitCard(Harness harness, Credentials credentials, String icoNumber, String testCard) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withIco(icoNumber);
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIcoWithAlert((nonClient.ico())))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsCommercialDebitCard(testCardLastNumbers));

        reportingId = "Ičo klienta " + nonClient.birthNumber();
        testCardForJira = testCard;
    }

    @TestCase(name = "Change Moto and Internet Transactions For Retail Standard Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9240")
    public void changeMotoIntForStandardRetailDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForStandardDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.standard.DC"));
    }

    @TestCase(name = "Change Moto and Internet Transactions For Retail Gold Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8734")
    public void changeMotoIntForGoldRetailDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForStandardDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.gold.DC"));
    }

    @TestCase(name = "Change Moto and Internet Transactions For USD Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9596")
    public void changeMotoIntForRetailUsdDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForStandardDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.usd.DC"));
    }

    @TestCase(name = "Change Moto and Internet Transactions For Eur Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9595")
    public void changeMotoIntForRetailEurDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForStandardDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.eur.DC"));
    }

    @TestCase(name = "Change Moto and Internet Transactions for Retail Smart Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9239")
    public void changeMotoIntForRetailSmartCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc2"));
        String testCard = harness.getConfig("cards_team.retail.smart.CC");
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRcWithAlert(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsRetailCreditCard(testCardLastNumbers));

        reportingId = "Rč klienta " + nonClient.birthNumber();
        testCardForJira = testCard;
    }

    @TestCase(name = "Change Moto and Internet Transactions for Retail Gold Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9594")
    public void changeMotoIntForRetailGoldCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc5"));
        String testCard = harness.getConfig("cards_team.retail.gold.CC");
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRcWithAlert(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsRetailCreditCard(testCardLastNumbers));

        reportingId = "Rč klienta " + nonClient.birthNumber();
        testCardForJira = testCard;
    }

    @TestCase(name = "Change Moto and Internet Transactions for Retail Account Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9593")
    public void changeMotoIntForRetailAccountCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc4"));
        String testCard = harness.getConfig("cards_team.retail.account.CC");
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRcWithAlert(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsRetailCreditCard(testCardLastNumbers));

        reportingId = "Rč klienta " + nonClient.birthNumber();
        testCardForJira = testCard;
    }

    @TestCase(name = "Change Moto and Internet Transactions for commercial DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9592")
    public void changeMotoIntForCommercialDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.DC"));
    }

    @TestCase(name = "Change Moto and Internet Transactions for commercial premium DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9591")
    public void changeMotoIntForCommercialPremiumDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.premium.DC"));
    }

    @TestCase(name = "Change Moto and Internet Transactions for commercial USD DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9590")
    public void changeMotoIntForCommercialUsdDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.USD"));
    }

    @TestCase(name = "Change Moto and Internet Transactions for commercial EUR DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9589")
    public void changeMotoIntForCommercialEurDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeMotoIntForCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.EUR"));
    }

    @TestCase(name = "Change Moto and Internet Transactions for MBC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9588")
    public void changeMotoIntForMBC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withIco(harness.getConfig("cards_team.commercial.ico.with.cards"));
        String testCard = harness.getConfig("cards_team.commercial.CC");
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIcoWithAlert(nonClient.ico()))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsMBC(testCardLastNumbers));

        reportingId = "Ičo klienta " + nonClient.ico();
        testCardForJira = testCard;
    }

    @TestCase(name = "Change Moto and Internet Transactions for Child Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9587")
    public void changeMotoIntForChildCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.child.rc"));
        String testCard = harness.getConfig("cards_team.child.card");
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findChildByRC(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().changeIntMotoTransactionsRetailDebitCard(testCardLastNumbers));

        reportingId = "Rč klienta " + nonClient.birthNumber();
        testCardForJira = testCard;
    }

    @AfterEach
    public void tearDown(Harness harness) {
        harness.store("reports.tmfj.execution.comment",
                reportingId + "\n Číslo karty: " + testCardForJira + "\n Status MOTO/INT: " + harness.get("MOTO_INFO") +
                        "\n" + harness.tasks().ufo().banka().cardsServicing().getPrintedPages());
    }
}
