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

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.KSNCoinSplits;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCurrencies;
import cz.moneta.test.dsl.kasanova.components.enums.KSNOriginDeposit;
import cz.moneta.test.dsl.kasanova.components.enums.KSNRelationShipToTheOwner;
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.section3.KSNFunction34Test;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 14) Vklad v měně účtu, HK")
public class KSNFunction14Test {

    private KSNFunction34Test function34test;
    private boolean doOpposite;
    private static final String PENIZE_NA_CESTE = "Penize na ceste";

    @Order(1)
    @JiraTestCase(id="PAY-T1323")
    @TestCase(name = "(Fce 14 - podlimit)")
    public void func14underLimit(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 14 UnderLimit) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction14()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .EnterFunction14()
            .depositAmount("200")
            .fillIdentificationAndSymbolsShort()
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_100_INPUT, "2")
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    @Order(2)
    @JiraTestCase(id="PAY-T1361")
    @TestCase(name = "(Fce 14 - mezilimit)")
    public void func14middleLimit(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 14 MiddleLimit) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction14()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .EnterFunction14()
            .depositAmount("50000")
            .fillIdentificationAndSymbolsLong()
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    @Order(3)
    @JiraTestCase(id="PAY-T1362")
    @TestCase(name = "(Fce 14 - nadlimit)")
    public void func14overLimit(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 14 OverLimit) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction14()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .EnterFunction14()
            .depositAmount("500000")
            .kasanovaDialogClickOK()
            .fillIdentificationAndSymbolsLong()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_5.getValue())
            .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    @Order(4)
    @JiraTestCase(id="PAY-T1363")
    @TestCase(name = "(Fce 14 - podlimit - cizí měna)")
    public void func14underLimitForeignCurrency(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 14 UnderLimit Foreign Currency) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction14()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction14()
            .depositAmount("20")
            .fillIdentificationAndSymbolsShort()
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_20_INPUT, "1")
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    @Order(5)
    @JiraTestCase(id="PAY-T1364")
    @TestCase(name = "(Fce 14 - mezilimit - cizí měna)")
    public void func14middleLimitForeignCurrency(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 14 MiddleLimit Foreign Currency) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction14()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .Currency(KSNCurrencies.USD_NAME.getValue())
            .EnterFunction14()
            .depositAmount("2500")
            .fillIdentificationAndSymbolsLong()
            .coinSplitTable(KSNCoinSplits.COINSPLIT_USD_100_INPUT, "25")
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

    @Order(6)
    @JiraTestCase(id="PAY-T1365")
    @TestCase(name = "(Fce 14 - nadlimit - cizí měna)")
    public void func14overLimitForeignCurrency(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 14 OverLimit Foreign Currency) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction14()
            .HK_AccountNameSelect(PENIZE_NA_CESTE)
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction14()
            .depositAmount("20000")
            .kasanovaDialogClickOK()
            .fillIdentificationAndSymbolsLong()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_5.getValue())
            .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_500_INPUT, "40")
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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