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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.kasanova.components.enums.KSNAccounts;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCurrencies;
import cz.moneta.test.dsl.kasanova.components.enums.KSNOriginDeposit;
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.section2.KSNFunction21Test;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 41) Výběr v jiné měně, BÚ")
public class KSNFunction41Test {
    private KSNFunction21Test function21test;
    private boolean doOpposite;
    
    @Order(1)
    @JiraTestCase(id="PAY-T1308")
    @TestCase(name = "(Fce 41 - podlimit)")
    public void func41underLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        underLimit(harness, banker, doOpposite);
    }

    public void underLimit(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {
        
        harness.log("---------------- (FUNCTION 41 UnderLimit) ----------------");
        
        if(doOpposite == true) {
            function21test = new KSNFunction21Test();
            function21test.underLimitWithDispo(harness, banker, false);
        }
        
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection4()
            .KSNFunction41()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction41()
            .withdrawAmount("500")
            .authPerson4()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();
        
        harness.log("---------------- (FUNCTION 41 UnderLimit) ----------------");
    } 
    
    @Order(2)
    @JiraTestCase(id="PAY-T1350")
    @TestCase(name = "(Fce 41 - mezilimit)")
    public void func41middleLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        middleLimit(harness, banker, doOpposite);
    }

    public void middleLimit(Harness harness, @Key(kasanova.banker) Credentials banker, boolean doOpposite) {
        
        harness.log("---------------- (FUNCTION 41 MiddleLimit) ----------------");
        
        if(doOpposite == true) {
            function21test = new KSNFunction21Test();
            function21test.middleLimitWithDispo(harness, banker, false);
        }
        
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection4()
            .KSNFunction41()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction41()
            .withdrawAmount("2000")
            .authPerson4()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();
        
        harness.log("---------------- (FUNCTION 41 MiddleLimit) ----------------");
    }  
    
    @Order(3)
    @JiraTestCase(id="PAY-T1351")
    @TestCase(name = "(Fce 41 - nadlimit)")
    public void func41overLimit(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        overLimit(harness, banker, verifyBanker, doOpposite);
    }

    public void overLimit(Harness harness, @Key(kasanova.banker) Credentials banker, @Key(kasanova.verifyBanker) Credentials verifyBanker, boolean doOpposite) {
        
        harness.log("---------------- (FUNCTION 41 OverLimit) ----------------");
        
        if(doOpposite == true) {
            function21test = new KSNFunction21Test();
            function21test.overLimitWithDispo(harness, banker, verifyBanker, false);
        }
        
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection4()
            .KSNFunction41()
            .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .Currency(KSNCurrencies.EUR_NAME.getValue())
            .EnterFunction41()
            .withdrawAmount("20000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_9.getValue())
            .authPerson4()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .doVerification(harness, "20000", KSNAccounts.CZK_206971718.getValue(), verifyBanker)
            .checkFunctionIsDone()
            .logOut();
        
        harness.log("---------------- (FUNCTION 41 OverLimit) ----------------");
    }  

    @Order(4)
    @JiraTestCase(id = "PAY-T1765")
    @TestCase(name = "(Fce 41 - přesměrování do funkce 31)")
    public void func41redirect(Harness harness, @Key(kasanova.banker) Credentials banker) {

        harness.log("---------------- START TEST (FUNCTION 41 Redirect) ----------------");
        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection4()
                .KSNFunction41()
                .CA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
                .Currency(KSNCurrencies.CZK_NAME.getValue())
                .EnterFunction31()
                .checkRedirect("31 - Výběr z BÚ v měně účtu")
                .backToMainMenu()
                .logOut();
        harness.log("---------------- END TEST (FUNCTION 41 Redirect) ----------------");
    }

}
