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 18) Vklad v měně účtu, Hromadný vklad")
public class KSNFunction18Test {

    private KSNFunction31Test function31test;
    private boolean doOpposite;
    private final String BU_CZK_609_206971718 = "609-206971718";

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

        harness.log("---------------- START TEST (FUNCTION 18 UnderLimitNoDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction18()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction18()
                .depositAmount("350")
                .firstDepositAmount("200")
                .firstDepositVarSymbol("1")
                .clickAddAnotherDeposit()
                .secondDepositAmount("150")
                .secondDepositVarSymbol("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_200_INPUT, "2")
                .fillIdentificationAndConstantSymbolMini()
                .clickPrintSmry()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

        harness.log("---------------- START TEST (FUNCTION 18 MiddleLimitNoDispo) ----------------");
        harness.withKasanova()
        .openLoginPage()
        .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
        .KSNSection1()
        .KSNFunction18()
        .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
        .enterFunction18()
        .depositAmount("49950")
        .firstDepositAmount("20000")
        .firstDepositVarSymbol("1")
        .clickAddAnotherDeposit()
        .secondDepositAmount("29950")
        .secondDepositVarSymbol("2")
        .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
        .fillIdentificationAndConstantSymbolLong()
        .clickPrintSmry()
        .dismissPrintWindow()
        .kasanovaDialogClickOK()
        .continueWithPrintAction()
        .kasanovaDialogClickYes()
        .dismissPrintWindow()
        .dismissPrintWindow()
        .continueWithSaveAction()
        .checkFunctionIsDone()
        .logOut();

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

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

    @Order(3)
    @JiraTestCase(id = "PAY-T1403")
    @TestCase(name = "(Fce 18 - nadlimit - 3.osoba)")
    public void func18overLimitNoDispo(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 18 OverLimitNoDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction18()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction18()
                .depositAmount("499500")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
                .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
                .firstDepositAmount("200000")
                .firstDepositVarSymbol("1")
                .clickAddAnotherDeposit()
                .secondDepositAmount("299500")
                .secondDepositVarSymbol("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .fillIdentificationAndConstantSymbolLong()
                .clickPrintSmry()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

        harness.log("---------------- START TEST (FUNCTION 18 UnderLimitWithDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction18()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction18()
                .depositAmount("400")
                .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_200_INPUT, "2")
                .firstDepositAmount("300")
                .firstDepositVarSymbol("1")
                .clickAddAnotherDeposit()
                .secondDepositAmount("100")
                .secondDepositVarSymbol("2")
                .clickPrintSmry()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

        harness.log("---------------- START TEST (FUNCTION 18 MiddleLimitWithDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction18()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction18()
                .depositAmount("50000")
                .firstDepositAmount("20000")
                .firstDepositVarSymbol("1")
                .clickAddAnotherDeposit()
                .secondDepositAmount("30000")
                .secondDepositVarSymbol("2")
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
                .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
                .clickPrintSmry()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

    @Order(6)
    @JiraTestCase(id = "PAY-T1406")
    @TestCase(name = "(Fce 18 - nadlimit - oprávněná osoba)")
    public void func18overLimitWithDispo(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 18 OverLimitWithDispo) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection1()
                .KSNFunction18()
                .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .enterFunction18()
                .depositAmount("500000")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_1.getValue())
                .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
                .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
                .firstDepositAmount("200000")
                .firstDepositVarSymbol("1")
                .clickAddAnotherDeposit()
                .secondDepositAmount("300000")
                .secondDepositVarSymbol("2")
                .clickPrintSmry()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

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

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction18()
            .MA_AccountNumber(BU_CZK_609_206971718)
            .enterFunction18()
            .backToMainMenu()
            .logOut();
        harness.log("---------------- END TEST (FUNCTION 18 ExternalAccForm) ----------------");
    }
}
