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

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.KSNCurrencies;
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.section4.KSNFunction41Test;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 21) Vklad v jiné měně, BÚ")
public class KSNFunction21Test {
    private KSNFunction41Test function41test;
    private boolean doOpposite;
    
    @Order(1)
    @JiraTestCase(id="PAY-T1309")
    @TestCase(name = "(Fce 21 - 3.osoba - podlimit)")
    public void func21underLimitNoDispo(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("---------------- (FUNCTION 21 UnderLimitNoDispo) ----------------");

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection2()
            .KSNFunction21()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction21()
            .depositAmount("500")
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_100_INPUT, "5")
            .fillFeeCoinsplit()
            .fillIdentificationAndSymbolsShort()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection2()
            .KSNFunction21()   
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction21()
            .depositAmount("2000")
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_500_INPUT, "4")
            .fillFeeCoinsplit()
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection2()
            .KSNFunction21()   
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction21()
            .depositAmount("16600")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
            .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_500_INPUT, "33")
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_100_INPUT, "1")
            .fillFeeCoinsplit()
            .fillIdentificationAndSymbolsLong()
            .continueWithPrintAction()
            .kasanovaDialogClickYes()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection2()
            .KSNFunction21()   
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction21()
            .depositAmount("500")
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_100_INPUT, "5")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection2()
            .KSNFunction21()   
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction21()
            .depositAmount("2000")
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_500_INPUT, "4")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection2()
            .KSNFunction21()   
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction21()
            .depositAmount("20000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_2.getValue())
            .relationToTheOwner(KSNRelationShipToTheOwner.VZTAH_K_MAJITELI_23.getValue())
            .authPerson(KSNPersons.VACLAV_KARTAK.getValue())
            .coinSplitTable(KSNCoinSplits.COINSPLIT_EUR_500_INPUT, "40")
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

        harness.log("---------------- (FUNCTION 21 OverLimitWithDispo) ----------------");
    }

    @Order(7)
    @JiraTestCase(id = "PAY-T1764")
    @TestCase(name = "(Fce 21 - přesměrování do funkce 11)")
    public void func21redirect(Harness harness, @Key(kasanova.banker) Credentials banker) {

        harness.log("---------------- START TEST (FUNCTION 21 Redirect) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection2()
                .KSNFunction21()
                .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .Currency(KSNCurrencies.CZK_NAME.getValue())
                .EnterFunction11()
                .checkRedirect("11 - Vklad v měně účtu na BÚ")
                .backToMainMenu()
                .logOut();
        harness.log("---------------- END TEST (FUNCTION 21 Redirect) ----------------");
    }

}
