package cz.moneta.test.regression.channels.digital.ib.newib.cards.blockprocesses.fop;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.DebitCardFeePlan;
import cz.moneta.test.dsl.ufo.banka.pages.cards.credit.CardTypeAndDesign;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.harness.annotations.EnableIfSet;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Order;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@Disabled("Test card setup will be done differently")
@TestScenarioWithOrder(name = "Debit cards blocking processes")
public class DebitCardsProcessesFop {
    String loginName;
    String password;
    String lastFourDigits;
    NewIbTasks newIbTasks;

    @BeforeAll
    protected void createDebitCard(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        String clientCif = harness.getConfig("nib.fop.cif");
        BankaTasks bankaTasks = harness.tasks().ufo().banka();

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findByCif(clientCif))
                .then(bankaTasks.newDebitCard().createDebitCard(CardTypeAndDesign.BUSINESS.getValue(), DebitCardFeePlan.FREE))
                .storeCardLastFourDigits();

        harness.storeGlobal("NEW_DEBIT_CARD_CREATED", "PASS");
    }

    @BeforeEach
    void setUp(Harness harness) {
        newIbTasks = harness.tasks().newIb();
        lastFourDigits = harness.getGlobal("LAST_FOUR_DIGITS");
        loginName = harness.getConfig("nib.fop.login-name");
        password = harness.getConfig("nib.client.password");
    }

    @EnableIfSet(globalKey = "NEW_DEBIT_CARD_CREATED")
    @Order(1)
    @TestCase(name = "Temporary block debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "SBO-T915")
    public void temporaryBlockCardFop(Harness harness) {
        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(loginName, password))
                .then(newIbTasks.getIntoBlockingScreen(lastFourDigits, "Neaktivní"))
                .clickBlockCardRadio()
                .clickContinue()
                .then(newIbTasks.smsKeyAuthorizationPopup())
                .blockMessageAppeared();

        harness.storeGlobal("DEBIT_CARD_BLOCKED", "PASS");
    }

    @EnableIfSet(globalKey = "DEBIT_CARD_BLOCKED")
    @Order(2)
    @TestCase(name = "Unblock debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "SBO-T916")
    public void unblockCardFop(Harness harness) {
        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(loginName, password))
                .then(newIbTasks.getIntoBlockingScreen(lastFourDigits, "Dočasně blokovaná"))
                .clickUnblockCardRadio()
                .clickContinue()
                .then(newIbTasks.smsKeyAuthorizationPopup())
                .unblockMessageAppeared();

        harness.storeGlobal("DEBIT_CARD_UNBLOCKED", "PASS");
    }

    @EnableIfSet(globalKey = "DEBIT_CARD_UNBLOCKED")
    @Order(3)
    @TestCase(name = "Cancel debit card", environments = {TST1, PPE})
    @JiraTestCase(id = "SBO-T917")
    public void cancelDebitCardFop(Harness harness) {
        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(loginName, password))
                .then(newIbTasks.getIntoBlockingScreen(lastFourDigits, "Neaktivní"))
                .clickCancelCardRadio()
                .clickContinue()
                .then(newIbTasks.smsKeyAuthorizationPopup())
                .cancelMessageAppeared()
                .clickBackToCard()
                .clickDetailsAndSettings()
                .checkCardDetailInfo("Zrušená");
    }
}