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

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;
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.section1.KSNFunction14Test;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 34) Výběr v měně účtu, HK")
public class KSNFunction34Test {

    private KSNFunction14Test function14test;
    private boolean doOpposite;
    private static final String PENIZE_NA_CESTE = "Penize na ceste";

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

    public void underLimit(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 34 UnderLimit) ----------------");

        if(doOpposite == true) {
            function14test = new KSNFunction14Test();
            function14test.underLimit(harness, banker, false);
        }

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction34()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .EnterFunction34()
            .withdrawAmount("200")
            .fillIdentificationAndSymbolsShort()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    public void middleLimit(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 34 MiddleLimit) ----------------");

        if(doOpposite == true) {
            function14test = new KSNFunction14Test();
            function14test.middleLimit(harness, banker, false);
        }

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction34()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .EnterFunction34()
            .withdrawAmount("50000")
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    public void overLimit(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 34 OverLimit) ----------------");

        if(doOpposite == true) {
            function14test = new KSNFunction14Test();
            function14test.overLimit(harness, banker, verifyBanker, false);
        }

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction34()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .EnterFunction34()
            .withdrawAmount("500000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_5.getValue())
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .doVerification(harness, "500000", KSNAccounts.UCET_PENIZE_NA_CESTE.getValue(), verifyBanker)
            .checkFunctionIsDone()
            .logOut();

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

    @Order(4)
    @JiraTestCase(id="PAY-T1368")
    @TestCase(name = "(Fce 34 - podlimit - cizí měna)")
    public void func34underLimitForeignCurrency(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        underLimitForeignCurrency(harness, banker, doOpposite);
    }

    public void underLimitForeignCurrency(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 34 UnderLimit Foreign Currency) ----------------");

        if(doOpposite == true) {
            function14test = new KSNFunction14Test();
            function14test.underLimitForeignCurrency(harness, banker, false);
        }

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction34()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction34()
            .withdrawAmount("20")
            .fillIdentificationAndSymbolsShort()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

        harness.log("---------------- END TEST (FUNCTION 34 UnderLimit Foreign Currency) ----------------");
    }

    @Order(5)
    @JiraTestCase(id="PAY-T1369")
    @TestCase(name = "(Fce 34 - mezilimit - cizí měna)")
    public void func34middleLimitForeignCurrency(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        middleLimitForeignCurrency(harness, banker, doOpposite);
    }

    public void middleLimitForeignCurrency(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 34 MiddleLimit Foreign Currency) ----------------");

        if(doOpposite == true) {
            function14test = new KSNFunction14Test();
            function14test.middleLimitForeignCurrency(harness, banker, false);
        }

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction34()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .Currency(KSNCurrencies.USD_NAME.getValue())
            .EnterFunction34()
            .withdrawAmount("2500")
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

        harness.log("---------------- END TEST (FUNCTION 34 MiddleLimit Foreign Currency) ----------------");
    }

    @Order(6)
    @JiraTestCase(id="PAY-T1370")
    @TestCase(name = "(Fce 34 - nadlimit - cizí měna)")
    public void func34overLimitForeignCurrency(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        overLimitForeignCurrency(harness, banker, verifyBanker, doOpposite);
    }

    public void overLimitForeignCurrency(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 34 OverLimit Foreign Currency) ----------------");

        if(doOpposite == true) {
            function14test = new KSNFunction14Test();
            function14test.overLimitForeignCurrency(harness, banker, verifyBanker, false);
        }

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction34()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction34()
            .withdrawAmount("20000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_3.getValue())
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .doVerification(harness, "20000", KSNAccounts.UCET_PENIZE_NA_CESTE.getValue(), verifyBanker)
            .checkFunctionIsDone()
            .logOut();

        harness.log("---------------- END TEST (FUNCTION 34 OverLimit Foreign Currency) ----------------");
    }
}
