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 limits on card")
public class CardsLimitChange {

    NonClient nonClient;
    String testCard;
    String reportingId;


    public void changeLimitRetailDc(Harness harness, Credentials credentials, String intLimit, String atmLimit, String posLimit, String birthNum, String cardNumber) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(birthNum);
        String testCardLastNumbers = StringUtils.right(cardNumber, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRcWithAlert(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().changeLimitOnDebitCardMainPart(testCardLastNumbers, intLimit, atmLimit, posLimit))
                .then(bankaTasks.cardsServicing().changeLimitOnDebitCardLastPart(harness));

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

    public void changeLimitCommercialDC(Harness harness, Credentials credentials, String intLimit, String atmLimit, String posLimit, String icoNum, String cardNumber) {
        nonClient = harness.data().newFVNonClient()
                .withIco(icoNum);
        String testCardLastNumbers = StringUtils.right(cardNumber, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByIcoWithAlert(nonClient.ico()))
                .then(bankaTasks.cardsServicing().changeLimitOnDebitCardMainPart(testCardLastNumbers, intLimit, atmLimit, posLimit))
                .then(bankaTasks.cardsServicing().changeLimitOnDebitCardLastPart(harness));

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

    @TestCase(name = "Limit change for plastic retail standard Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T351")
    public void changeLimitPlasticStandardDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.standard.DC"));
    }

    @TestCase(name = "Limit change for virtual retail standard Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9795")
    public void changeLimitVirtualStandardDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.standard.virtual.DC"));
    }

    @TestCase(name = "Limit change for pride virtual retail standard Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9796")
    public void changeLimitPrideVirtualStandardDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.standard.virtual.pride.DC"));
    }

    @TestCase(name = "Limit change for retail plastic gold Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9797")
    public void changeLimitPlasticGoldDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.gold.DC"));
    }

    @TestCase(name = "Limit change for retail virtual gold Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9798")
    public void changeLimitVirtualGoldDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.virtual.gold.DC"));
    }

    @TestCase(name = "Limit change for eur Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9799")
    public void changeLimitEurDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "1200", "1200", "1200", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.eur.DC"));
    }

    @TestCase(name = "Limit change for usd Dc", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9800")
    public void changeLimitUsdDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitRetailDc(harness, credentials, "1200", "1200", "1200", harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.usd.DC"));
    }

    @TestCase(name = "Limit change for retail smart CC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8709")
    public void changeLimitRetailSmartCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc2"));
        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().changeLimitRetailSmartCreditCard(testCardLastNumbers, "9000", "9000", "9000"));

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

    @TestCase(name = "Limit change for retail gold CC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9801")
    public void changeLimitRetailGoldCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc5"));
        testCard = harness.getConfig("cards_team.retail.gold.CC");
        String testCardLastNumbers = StringUtils.right(testCard, 4);
        reportingId = nonClient.birthNumber();

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

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

    @TestCase(name = "Limit change for retail account CC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9802")
    public void changeLimitRetailAccountCC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc4"));
        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().changeLimitRetailSmartCreditCard(testCardLastNumbers, "10000", "10000", "10000"));

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

    @TestCase(name = "Limit change for child DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9806")
    public void changeLimitChildDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.child.rc"));
        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().changeLimitOnDebitCardMainPart(testCardLastNumbers, "400", "400", "400"));

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

    @TestCase(name = "Limit change for MBC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8710")
    public void changeLimitMBC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        nonClient = harness.data().newFVNonClient()
                .withIco(harness.getConfig("cards_team.commercial.ico.with.cards"));
        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().changeLimitMBC(testCardLastNumbers, "4200", "4200", "4200"));

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

    @TestCase(name = "Limit change for commercial DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8728")
    public void changeLimitStandardCommercialDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitCommercialDC(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.DC"));
    }

    @TestCase(name = "Limit change for premium commercial DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9805")
    public void changeLimitPremiumCommercialDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitCommercialDC(harness, credentials, "42000", "42000", "42000", harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.premium.DC"));
    }

    @TestCase(name = "Limit change for commercial eur DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9804")
    public void changeLimitCommercialEurDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitCommercialDC(harness, credentials, "1200", "1200", "1200", harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.EUR"));
    }

    @TestCase(name = "Limit change for commercial usd DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9803")
    public void changeLimitCommercialUsdDC(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        changeLimitCommercialDC(harness, credentials, "1200", "1200", "1200", harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.USD"));
    }

    @AfterEach
    public void tearDown(Harness harness) {
        harness.store("reports.tmfj.execution.comment",
                reportingId +
                        "\n Číslo karty: " + testCard +
                        "\n Limity změněny na " +
                        "\n ATM " + harness.get("LIM_BANK_PAYMENT_CHANGED") +
                        "\n INT " + harness.get("LIM_INT_PAYMENT_CHANGED") +
                        "\n MOTO " + harness.get("LIM_MOTO_PAYMENT_CHANGED") +
                        "\n" + harness.tasks().ufo().banka().cardsServicing().getPrintedPages());
    }
}
