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

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.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 static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Teller must be able to block card")
public class BlockCard {

    NonClient nonClient;

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

    @TestCase(name = "Permanently block a card", environments = {TST1, PPE})
    public void permanentlyBlockCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        String testCard = harness.getConfig("cards_team.retail.standard.DC.for.block");
        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().permaBlockCard(testCardLastNumbers));

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