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 DCC transactions")
public class ChangeDccSettingOnCards {

    String reportingId;
    String testCardForJira;

    public void changeDccForStandardDebitCard(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().changeDccSettingOnRetailDebitCard(testCardLastNumbers))
        ;

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

    public void changeDccForCommercialDebitCard(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().changeDccSettingOnCommercialDebitCard(testCardLastNumbers));

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

    public void changeDccForRetailCreditCard(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().changeDccSettingOnRetailCreditCard(testCardLastNumbers));

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

    @TestCase(name = "Change DCC Transactions Setting For Retail Standard Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11030")
    public void changeDccForStandardRetailDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForStandardDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.standard.DC"));
    }

    @TestCase(name = "Change DCC Transactions Setting For Retail Gold Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11031")
    public void changeDccForGoldRetailDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForStandardDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.gold.DC"));
    }

    @TestCase(name = "Change DCC Transactions Setting for Retail Smart Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11035")
    public void changeDccForRetailSmartCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForRetailCreditCard(harness, credentials, harness.getConfig("cards_team.retail.rc2"), harness.getConfig("cards_team.retail.smart.CC"));
    }

    @TestCase(name = "Change DCC Transactions Setting for Retail Gold Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11036")
    public void changeDccForRetailGoldCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForRetailCreditCard(harness, credentials, harness.getConfig("cards_team.retail.rc5"), harness.getConfig("cards_team.retail.gold.CC"));
    }

    @TestCase(name = "Change DCC Transactions Setting for Retail Account Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11037")
    public void changeDccForRetailAccountCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForRetailCreditCard(harness, credentials, harness.getConfig("cards_team.retail.rc4"), harness.getConfig("cards_team.retail.account.CC"));
    }

    @TestCase(name = "Change DCC Transactions Setting for commercial DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11066")
    public void changeDccForCommercialDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.DC"));
    }

    @TestCase(name = "Change DCC Transactions Setting for commercial premium DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11067")
    public void changeDccForCommercialPremiumDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeDccForCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.premium.DC"));
    }

    @TestCase(name = "Change DCC Transactions Setting for MBC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11070")
    public void changeDccForMBC(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().changeDccSettingOnMBC(testCardLastNumbers));

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

    @TestCase(name = "Change DCC Transactions Setting for Child Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T11034")
    public void changeDccForChildCard(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().changeDccSettingOnRetailDebitCard(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 DCC: " + harness.get("DCC_INFO") +
                        "\n" + harness.tasks().ufo().banka().cardsServicing().getPrintedPages());
    }
}
