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

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.Order;
import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCoinSplits;
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;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 61) Směnárna, Nákup valut bankou")
public class KSNFunction61Test {

    KSNFunction62Test function62test;
    private boolean doOpposite;

    @Order(1)
    @JiraTestCase(id = "PAY-T1692")
    @TestCase(name = "(Fce 61 - podlimit)")
    public void func61underLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        underLimit(harness, banker, doOpposite);
    }
    public void underLimit(Harness harness, Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 61 UnderLimit) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection6()
                .KSNFunction61()
                .enterFunction61()
                .smenaAmount("5")
                .coinSplitTable(KSNCoinSplits.SMENA_COINSPLIT_USD_5_INPUT, "1")
                .fillIdentificationAndSymbolsSmenaShort()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

        if (doOpposite) {
            function62test = new KSNFunction62Test();
            function62test.underLimit(harness, banker, false);
        }
        harness.log("---------------- END TEST (FUNCTION 61 UnderLimit) ----------------");
    }

    @Order(2)
    @JiraTestCase(id = "PAY-T1693")
    @TestCase(name = "(Fce 61 - mezilimit)")
    public void func61middleLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        middleLimit(harness, banker, doOpposite);
    }
    public void middleLimit(Harness harness, Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 61 MiddleLimit) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection6()
                .KSNFunction61()
                .enterFunction61()
                .smenaAmount("1600")
                .kasanovaDialogClickOK()
                .coinSplitTable(KSNCoinSplits.SMENA_COINSPLIT_USD_100_INPUT, "16")
                .fillIdentificationAndSymbolsSmenaLong()
                .clickPrintInfo()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

        if (doOpposite) {
            function62test = new KSNFunction62Test();
            function62test.middleLimit(harness, banker, false);
        }
        harness.log("---------------- END TEST (FUNCTION 61 MiddleLimit) ----------------");
    }

    @Order(3)
    @JiraTestCase(id = "PAY-T1694")
    @TestCase(name = "(Fce 61 - nadlimit)")
    public void func61overLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        overLimit(harness, banker, doOpposite);
    }
    public void overLimit(Harness harness, Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 61 OverLimit) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection6()
                .KSNFunction61()
                .enterFunction61()
                .smenaAmount("18000")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
                .originePurpose2(KSNOriginDeposit.PUVOD_VKLADU_3.getValue())
                .coinSplitTable(KSNCoinSplits.SMENA_COINSPLIT_USD_100_INPUT, "180")
                .fillIdentificationAndSymbolsSmenaLong()
                .clickPrintInfo()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

        if (doOpposite) {
            function62test = new KSNFunction62Test();
            function62test.overLimit(harness, banker, false);
        }
        harness.log("---------------- END TEST (FUNCTION 61 OverLimit) ----------------");
    }
}
