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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
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.BeforeAll;
import org.junit.jupiter.api.Disabled;

import java.util.ArrayList;
import java.util.List;

import static cz.moneta.test.harness.annotations.Environment.*;

@TestScenario(name = "Teller must be able to cancel a card")
public class DebitCardCancellation {

    NonClient nonClient;

    @BeforeAll
    public void setup(Harness harness) {
        nonClient = harness.data().newFVNonClient()
                .withBirthNumber(harness.getConfig("cards_team.retail.rc"));
    }


    @TestCase(name = "Cancel Card", environments = {TST1, PPE, EDU})
    @JiraTestCase(id = "CT-T7154")
    public void cancellationOfCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        String testCard = harness.getConfig("cards_team.retail.standard.DC.for.cancel");
        String testCardLastNumbers = StringUtils.right(testCard, 4);

        BankaTasks bankaTasks = harness.tasks().ufo().banka();
        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRC(nonClient.birthNumber()))
                .then(bankaTasks.cardsServicing().cancelDebitCard(testCardLastNumbers));
        harness.store("reports.tmfj.execution.comment", "Rč klienta " + nonClient.birthNumber() + "\n Číslo karty: " + testCard);
    }

    @Disabled
    @TestCase(name = "Multiple Cancel Card", environments = {TST1, PPE, EDU})
    public void cancellationOfMoreCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        List<String> cardsToCancel = new ArrayList<>();
        cardsToCancel.add("0040");
        cardsToCancel.add("3240");

        BankaTasks bankaTasks = harness.tasks().ufo().banka();

        HKO101_S001_MainClientPage window = harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByRC(nonClient.birthNumber()));

        for (String cardNum : cardsToCancel) {
            window = window
                    .then(bankaTasks.cardsServicing().cancelDebitCard(cardNum));
        }
    }
}
