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.KSNAccounts;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCoinSplits;
import cz.moneta.test.dsl.kasanova.components.enums.KSNOriginDeposit;
import cz.moneta.test.dsl.kasanova.components.enums.KSNPersons;
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.KSNFunction31Test;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 16) Vklad v měně účtu, Odvod uzavřenými obaly")
public class KSNFunction16Test {

    private KSNFunction31Test function31test;
    private boolean doOpposite;

    @Order(1)
    @JiraTestCase(id = "PAY-T1339")
    @TestCase(name = "(Fce 16 - podlimit - 3.osoba)")
    public void func16underLimitNoDispo(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        harness.log("---------------- START TEST (FUNCTION 16 UnderLimitNoDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction16()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction16()
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_200_INPUT, "2")
                .fillIdentificationAndSymbolsShort()
                .continueWithPrintAction()
                .kasanovaDialogClickOK()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 16 UnderLimitNoDispo) ----------------");
    }

    @Order(2)
    @JiraTestCase(id = "PAY-T1375")
    @TestCase(name = "(Fce 16 - mezilimit - 3.osoba)")
    public void func16middleLimitNoDispo(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        harness.log("---------------- START TEST (FUNCTION 16 MiddleLimitNoDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction16()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction16()
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .kasanovaDialogClickOK()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 16 MiddleLimitNoDispo) ----------------");
    }

    @Order(3)
    @JiraTestCase(id = "PAY-T1376")
    @TestCase(name = "(Fce 16 - nadlimit - 3.osoba)")
    public void func16overLimitNoDispo(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        harness.log("---------------- START TEST (FUNCTION 16 OverLimitNoDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction16()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction16()
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
                .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
                .continueWithPrintAction()
                .kasanovaDialogClickOK()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 16 OverLimitNoDispo) ----------------");
    }

    @Order(4)
    @JiraTestCase(id = "PAY-T1377")
    @TestCase(name = "(Fce 16 - podlimit - oprávněná osoba)")
    public void func16underLimitWithDispo(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        harness.log("---------------- START TEST (FUNCTION 16 UnderLimitWithDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction16()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction16()
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_200_INPUT, "2")
                .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
                .fillIdentificationAndSymbolsMini()
                .continueWithPrintAction()
                .kasanovaDialogClickOK()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 16 UnderLimitWithDispo) ----------------");
    }

    @Order(5)
    @JiraTestCase(id = "PAY-T1378")
    @TestCase(name = "(Fce 16 - mezilimit - oprávněná osoba)")
    public void func16middleLimitWithDispo(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        harness.log("---------------- START TEST (FUNCTION 16 MiddleLimitWithDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction16()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction16()
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
                .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
                .fillIdentificationAndSymbolsMini()
                .continueWithPrintAction()
                .kasanovaDialogClickOK()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 16 MiddleLimitWithDispo) ----------------");
    }

    @Order(6)
    @JiraTestCase(id = "PAY-T1379")
    @TestCase(name = "(Fce 16 - nadlimit - oprávněná osoba)")
    public void func16overLimitWithDispo(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));

        harness.log("---------------- START TEST (FUNCTION 16 OverLimitWithDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction16()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction16()
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
                .fillIdentificationAndSymbolsMini()
                .continueWithPrintAction()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_1.getValue())
                .continueWithPrintAction()
                .kasanovaDialogClickOK()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 16 OverLimitWithDispo) ----------------");
    }

}
