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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
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 org.apache.commons.lang.StringUtils;

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 show PIN in IB")
public class CardsIbTests {

    Credentials clientCredentials;

    @TestCase(name = "Show Pin on a retail Standard Debit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T334")
    public void showPinOnRetailDebitCard(Harness harness) {
        String accountNumber = harness.getConfig("cards_team.retail.account.number7");
        String testCard = harness.getConfig("cards_team.retail.standard.DC.for.IB");
        String testCardLastNumbers = StringUtils.right(testCard, 4);
        String birthNumber = harness.getConfig("cards_team.retail.rc3");

        clientCredentials = harness.tasks()
                .udebs()
                .findCredentialsByRC(birthNumber);

        NewIbTasks newIbTasks = harness.tasks().newIb();
        harness.withNewIb().
                openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.showPinOnDebitCard(accountNumber, testCardLastNumbers));

        harness.store("reports.tmfj.execution.comment", "Rč klienta " + birthNumber + "\n Číslo karty:" + testCard);
    }

    @TestCase(name = "Show Pin on a retail Smart Credit Card", environments = {TST1, PPE})
    @JiraTestCase(id = "CT-T333")
    public void showPinOnRetailCreditCard(Harness harness) {
        String testCard = harness.getConfig("cards_team.retail.standard.CC.for.IB");
        String testCardLastNumbers = StringUtils.right(testCard, 4);
        String birthNumber = harness.getConfig("cards_team.retail.rc3");

        clientCredentials = harness.tasks()
                .udebs()
                .findCredentialsByRC(birthNumber);

        NewIbTasks newIbTasks = harness.tasks().newIb();
        harness.withNewIb().
                openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.showPinOnCreditCard(testCardLastNumbers));

        harness.store("reports.tmfj.execution.comment", "Rč klienta " + birthNumber + "\n Číslo karty:" + testCard);
    }
}