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.KSNFunction33Test;

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

    private KSNFunction33Test function33test;
    private boolean doOpposite;
    private final String VK_CZK_2110_3226830764 = "2110-3226830764";

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

    public void underLimitNoDispo(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 12 UnderLimitNoDispo) ----------------");

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction12()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction12()
                .depositAmount("400")
                .lineNumber("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_200_INPUT, "2")
                .fillIdentificationAndSymbolsShort()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

    public void middleLimitNoDispo(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 12 MiddleLimitNoDispo) ----------------");

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction12()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction12()
                .depositAmount("50000")
                .lineNumber("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

    public void overLimitNoDispo(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 12 OverLimitNoDispo) ----------------");

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction12()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction12()
                .depositAmount("500000")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_8.getValue())
                .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_25.getValue())
                .lineNumber("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .fillIdentificationAndSymbolsLong()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

    public void underLimitWithDispo(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 12 UnderLimitWithDispo) ----------------");

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction12()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction12()
                .depositAmount("400")
                .lineNumber("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_200_INPUT, "2")
                .authPerson(KSNPersons.LEOS_CHALUPA.getValue())
                .fillIdentificationAndSymbolsForDepositbook()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

    public void middleLimitWithDispo(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 12 MiddleLimitWithDispo) ----------------");

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction12()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction12()
                .depositAmount("50000")
                .lineNumber("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
                .authPerson(KSNPersons.LEOS_CHALUPA.getValue())
                .fillIdentificationAndSymbolsForDepositbook()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

    public void overLimitWithDispo(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker, boolean doOpposite) {

        harness.log("---------------- START TEST (FUNCTION 12 OverLimitWithDispo) ----------------");

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction12()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction12()
                .depositAmount("500000")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_8.getValue())
                .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_25.getValue())
                .lineNumber("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .authPerson(KSNPersons.LEOS_CHALUPA.getValue())
                .fillIdentificationAndSymbolsForDepositbook()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

    @Order(7)
    @JiraTestCase(id="PAY-T1876")
    @TestCase(name = "(Fce 12 - ext. tvar uctu)")
    public void func12externalAccForm(Harness harness, @Key(kasanova.banker) Credentials banker) {
        harness.log("---------------- START TEST (FUNCTION 12 ExternalAccForm) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction12()
            .MA_AccountNumber(VK_CZK_2110_3226830764)
            .enterFunction12()
            .backToMainMenu()
            .logOut();
        harness.log("---------------- END TEST (FUNCTION 12 ExternalAccForm) ----------------");
    }

}
