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

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.section4.KSNFunction42Test;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 22) Vklad v jiné měně, HK")
public class KSNFunction22Test {

    private KSNFunction42Test function42test;
    private boolean doOpposite;
    private static final String PENIZE_NA_CESTE = "Penize na ceste";

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

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection2()
                .KSNFunction22()
                .HK2_AccountNameSelect(PENIZE_NA_CESTE)
                .Currency(KSNCurrencies.USD.getValue())
                .EnterFunction22()
                .depositAmount("500")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_500_INPUT, "1")
                .fillIdentificationAndSymbolsShort()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

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

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

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

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

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection2()
                .KSNFunction22()
                .HK2_AccountNameSelect(PENIZE_NA_CESTE)
                .Currency(KSNCurrencies.USD.getValue())
                .EnterFunction22()
                .depositAmount("500000")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
                .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_22.getValue())
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

}
