package cz.moneta.test.regression.transactional.payments.cash.kasanova.section4;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.kasanova.components.enums.KSNAccounts;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCurrencies;
import cz.moneta.test.dsl.kasanova.components.enums.KSNOriginDeposit;
import cz.moneta.test.dsl.util.credentials.Keys.kasanova;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.NonConcurrentTestScenario;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import cz.moneta.test.regression.transactional.payments.cash.kasanova.section2.KSNFunction21Test;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 43) Výběr v jiné měně, BÚ - třetí osoba")
public class KSNFunction43Test {
    private KSNFunction21Test function21test;
    private boolean doOpposite;

    @Order(1)
    @JiraTestCase(id="PAY-T1321")
    @TestCase(name = "(Fce 43 - podlimit)")
    public void func43underLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        if(doOpposite == true) {
            function21test = new KSNFunction21Test();
            function21test.underLimitWithDispo(harness, banker, false);
        }

        harness.log("---------------- START TEST (FUNCTION 43 UnderLimit) ----------------");
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection4()
            .KSNFunction43()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction43()
            .withdrawAmount("500")
            .fillIdentificationAndSymbolsShort()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

        harness.log("---------------- END TEST (FUNCTION 43 UnderLimit) ----------------");
    }

    @Order(2)
    @JiraTestCase(id="PAY-T1354")
    @TestCase(name = "(Fce 43 - mezilimit)")
    public void func43middleLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        if(doOpposite == true) {
            function21test = new KSNFunction21Test();
            function21test.middleLimitWithDispo(harness, banker, false);
        }

        harness.log("---------------- START TEST (FUNCTION 43 MiddleLimit) ----------------");
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection4()
            .KSNFunction43()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction43()
            .withdrawAmount("2000")
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

        harness.log("---------------- END TEST (FUNCTION 43 MiddleLimit) ----------------");
    }

    @Order(3)
    @JiraTestCase(id="PAY-T1355")
    @TestCase(name = "(Fce 43 - nadlimit)")
    public void func43overLimit(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        if(doOpposite == true) {
            function21test = new KSNFunction21Test();
            function21test.overLimitWithDispo(harness, banker, verifyBanker, false);
        }

        harness.log("---------------- START TEST (FUNCTION 43 OverLimit) ----------------");
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection4()
            .KSNFunction43()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction43()
            .withdrawAmount("20000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_10.getValue())
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .doVerification(harness, "20000", KSNAccounts.CZK_206971718.getValue(), verifyBanker)
            .checkFunctionIsDone()
            .logOut();

        harness.log("---------------- END TEST (FUNCTION 43 OverLimit) ----------------");
    }

    @Order(4)
    @JiraTestCase(id = "PAY-T1766")
    @TestCase(name = "(Fce 43 - přesměrování do funkce 36)")
    public void func43redirect(Harness harness, @Key(kasanova.banker) Credentials banker) {

        harness.log("---------------- START TEST (FUNCTION 43 Redirect) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection4()
                .KSNFunction43()
                .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .Currency(KSNCurrencies.CZK_NAME.getValue())
                .EnterFunction36()
                .checkRedirect("36 - Výběr z běžného účtu v měně účtu třetí osob")
                .backToMainMenu()
                .logOut();
        harness.log("---------------- END TEST (FUNCTION 43 Redirect) ----------------");
    }

}
