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

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.KSNCoinSplits;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCurrencies;
import cz.moneta.test.dsl.kasanova.components.enums.KSNGender;
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.KSNFunction22Test;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 42) Výběr v jiné měně, HK")
public class KSNFunction42Test {

    private KSNFunction22Test function22test;
    private boolean doOpposite;
    private static final String PENIZE_NA_CESTE = "Penize na ceste";

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

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

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection4()
                .KSNFunction42()
                .HK2_AccountNameSelect(PENIZE_NA_CESTE)
                .Currency(KSNCurrencies.USD.getValue())
                .EnterFunction42()
                .calculateWithdrawAmount(500)
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_500_INPUT, "1")
                .fillIdentificationAndSymbolsShort()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection4()
                .KSNFunction42()
                .HK2_AccountNameSelect(PENIZE_NA_CESTE)
                .Currency(KSNCurrencies.USD.getValue())
                .EnterFunction42()
                .calculateWithdrawAmount(40000)
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "8")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection4()
                .KSNFunction42()
                .HK2_AccountNameSelect(PENIZE_NA_CESTE)
                .Currency(KSNCurrencies.USD.getValue())
                .EnterFunction42()
                .calculateWithdrawAmount(500000)
                .sex(KSNGender.MAN.getValue())
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_1.getValue())
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .doVerification(harness, KSNAccounts.UCET_PENIZE_NA_CESTE.getValue(), verifyBanker)
                .checkFunctionIsDone()
                .logOut();

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

}
