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 telephone number for 3D Secure payments")
public class Change3dSecureNumberOnCards {

    String reportingId;
    String testCardForJira;

    public void change3dSecureRetailDebitCard(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().change3dSecureNumberRetailDebitCard(testCardLastNumbers));

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

    public void change3dSecureCommercialDebitCard(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().change3dSecureNumberCommercialDebitCard(testCardLastNumbers));

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

    @TestCase(name = "Change 3D Secure Number for Standard Debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8736")
    public void change3dSecureRetailStandardDebitCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureRetailDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.standard.DC"));
    }

    @TestCase(name = "Change 3D Secure Number for Gold Debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8716")
    public void change3dSecureRetailGoldDebitCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureRetailDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.gold.DC"));
    }

    @TestCase(name = "Change 3D Secure Number for Eur Debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9601")
    public void change3dSecureRetailEurCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureRetailDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.eur.DC"));
    }

    @TestCase(name = "Change 3D Secure Number for Usd Debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9600")
    public void change3dSecureRetailUsdDebitCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureRetailDebitCard(harness, credentials, harness.getConfig("cards_team.retail.rc"), harness.getConfig("cards_team.retail.usd.DC"));
    }

    @TestCase(name = "Change 3D Secure Number for Smart Credit card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8721")
    public void change3dSecureRetailSmartCreditCard(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().change3dSecureNumberRetailCreditCard(testCardLastNumbers));

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

    @TestCase(name = "Change 3D Secure Number for gold Credit card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8702")
    public void change3dSecureRetailGoldCreditCard(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().change3dSecureNumberRetailCreditCard(testCardLastNumbers));

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

    @TestCase(name = "Change 3D Secure Number for credit account", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8722")
    public void change3dSecureRetailCreditAccountCreditCard(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().change3dSecureNumberRetailCreditCard(testCardLastNumbers));

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

    @TestCase(name = "Change 3D Secure Number for child card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8701")
    public void change3dSecureChildCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        NonClient nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.child.rc"))
                .withIdNumber(harness.getConfig("cards_team.child.op"));

        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().change3dSecureNumberChildCard(testCardLastNumbers, nonClient.idNumber()));

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

    @TestCase(name = "Change 3D Secure Number for MBC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T8729")
    public void change3dSecureMbc(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().change3dSecureNumberMbc(testCardLastNumbers));

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

    @TestCase(name = "Change 3D Secure Number for commercial DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T5607")
    public void change3dSecureCommercialDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.DC"));
    }

    @TestCase(name = "Change 3D Secure Number for commercial premium DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9599")
    public void change3dSecureCommercialPremiumDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.premium.DC"));
    }

    @TestCase(name = "Change 3D Secure Number for commercial eur DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9597")
    public void change3dSecureCommercialEurDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureCommercialDebitCard(harness, credentials, harness.getConfig("cards_team.commercial.ico.with.cards"), harness.getConfig("cards_team.commercial.EUR"));
    }

    @TestCase(name = "Change 3D Secure Number for commercial usd DC", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T9598")
    public void change3dSecureCommercialUsdDc(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        change3dSecureCommercialDebitCard(harness, credentials, 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: " + testCardForJira
                        + "\n" + harness.tasks().ufo().banka().cardsServicing().getPrintedPages());
    }
}
