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

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.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;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;

import static cz.moneta.test.dsl.util.credentials.Keys.kasanova;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 11) Vklad v měně účtu, BÚ)")
public class KSNFunction11Test {
    private KSNFunction31Test function31test;
    private boolean doOpposite;
    private final String BU_CZK_609_206971718 = "609-206971718";

    @Order(1)
    @JiraTestCase(id="PAY-T1287")
    @TestCase(name = "(Fce 11 - 3.osoba - podlimit)")
    public void func11underLimitNoDispo(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 11 UnderLimitNoDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()   
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction11()
            .depositAmount("350")
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_100_INPUT, "4")
            .fillIdentificationAndSymbolsShort()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 11 UnderLimitNoDispo) ----------------");
    }
    
    @Order(2)
    @JiraTestCase(id="PAY-T1343")
    @TestCase(name = "(Fce 11 - 3.osoba - mezilimit")
    public void func11middleLimitNoDispo(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 11 MiddleLimitNoDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction11()
            .depositAmount("49950")
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 11 MiddleLimitNoDispo) ----------------");
    }
    
    @Order(3)
    @JiraTestCase(id="PAY-T1344")
    @TestCase(name = "(Fce 11 - 3.osoba - nadlimit")
    public void func11overLimitNoDispo(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 11 OverLimitNoDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction11()
            .depositAmount("499500")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
            .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 11 OverLimitNoDispo) ----------------");
    }
    
    @Order(4)
    @JiraTestCase(id="PAY-T1345")
    @TestCase(name = "(Fce 11 - oprávněná osoba - podlimit)")
    public void func11underLimitWithDispo(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 11 UnderLimitWithDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()   
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction11()
            .depositAmount("400")
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_100_INPUT, "4")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 11 UnderLimitWithDispo) ----------------");
    }
    
    @Order(5)
    @JiraTestCase(id="PAY-T1346")
    @TestCase(name = "(Fce 11 - oprávněná osoba - mezilimit")
    public void func11middleLimitWithDispo(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 11 MiddleLimitWithDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction11()
            .depositAmount("50000")
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "10")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 11 MiddleLimitWithDispo) ----------------");
    }
    
    @Order(6)
    @JiraTestCase(id="PAY-T1347")
    @TestCase(name = "(Fce 11 - oprávněná osoba - nadlimit")
    public void func11overLimitWithDispo(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 11 OverLimitWithDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction11()
            .depositAmount("500000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
            .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_CZK_5000_INPUT, "100")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

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

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

    @Order(8)
    @JiraTestCase(id="PAY-T2825")
    @TestCase(name = "(Fce 11 - Vklad 100EUR na učet v jiné měně)")
    public void func11underLimit100EUR(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        underLimit100EUR(harness, banker, doOpposite);
    }

    public void underLimit100EUR(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 11 UnderLimit100EUR) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection1()
            .KSNFunction11()
            .MA_AccountNumber(KSNAccounts.CZK_215667013.getValue())
            .EnterFunction11()
            .depositAmount("100")
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_50_INPUT, "2")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- END TEST (FUNCTION 11 UnderLimit100EUR) ----------------");
    }
}
