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

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("New card creation not working")
@TestScenarioWithOrder(name = "Debit cards blocking processes")
public class DebitCardsProcessesPo {
    String loginName;
    String password;
    String lastFourDigits;
    NewIbTasks newIbTasks;

    @BeforeAll
    protected void createDebitCardPo(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        String clientIco = harness.getConfig("nib.po.ico");

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

        harness.withUfo()
                .openLoginPage()
                .then(bankaTasks.login().withCredentialsAndTurnOffSignpad(credentials))
                .then(bankaTasks.search().findLegalRepresentativeByIco(clientIco))
                .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.po.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-T918")
    public void temporaryBlockDebitCardPo(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-T922")
    public void unblockDebitCardPo(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-T920")
    public void cancelDebitCardPo(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á");
    }
}