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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.kasanova.components.enums.KSNAccounts;
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.section1.KSNFunction11Test;
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 31) Výběr v měně účtu, BÚ")
public class KSNFunction31Test {
    private KSNFunction11Test function11test;
    private boolean doOpposite;
    private final String BU_CZK_609_206971718 = "609-206971718";

    @Order(1)
    @JiraTestCase(id="PAY-T1299")
    @TestCase(name = "(Fce 31 - podlimit)")
    public void func31underLimit(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("---------------- START TEST (FUNCTION 31 UnderLimit) ----------------");
        
        if(doOpposite == true) {
            function11test = new KSNFunction11Test();
            function11test.underLimitWithDispo(harness, banker, false);
        }
        
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction31()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction31()
            .withdrawAmount("400")
            .authPerson4()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();
        
        harness.log("---------------- END TEST (FUNCTION 31 UnderLimit) ----------------");
    }    
    
    @Order(2)
    @JiraTestCase(id="PAY-T1348")
    @TestCase(name = "(Fce 31 - mezilimit)")
    public void func31middleLimit(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("---------------- START TEST (FUNCTION 31 MiddleLimit) ----------------");
        
        if(doOpposite == true) {
            function11test = new KSNFunction11Test();
            function11test.middleLimitWithDispo(harness, banker, false);
        }      
        
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction31()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction31()
            .withdrawAmount("50000")
            .authPerson4()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();
            
        harness.log("---------------- END TEST (FUNCTION 31 MiddleLimit) ----------------");
    }
    
    @Order(3)
    @JiraTestCase(id="PAY-T1349")
    @TestCase(name = "(Fce 31 - nadlimit)")
    public void func31overLimit(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("---------------- START TEST (FUNCTION 31 OverLimit) ----------------");
        
        if(doOpposite == true) {
            function11test = new KSNFunction11Test();
            function11test.overLimitWithDispo(harness, banker, verifyBanker, false);
        }      
        
        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction31()
            .MA_AccountNumber(KSNAccounts.CZK_206971718.getValue())
            .EnterFunction31()
            .withdrawAmount("500000")
            .kasanovaDialogClickOK()
            .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_11.getValue())
            .authPerson4()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .doVerification(harness, "500000", KSNAccounts.CZK_206971718.getValue(), verifyBanker)
            .checkFunctionIsDone()
            .logOut();
        
        harness.log("---------------- END TEST (FUNCTION 31 OverLimit) ----------------");
    }

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction31()
            .MA_AccountNumber(BU_CZK_609_206971718)
            .EnterFunction31()
            .backToMainMenu()
            .logOut();
        harness.log("---------------- END TEST (FUNCTION 31 ExternalAccForm) ----------------");
    }

    @Order(5)
    @JiraTestCase(id="PAY-T2826")
    @TestCase(name = "(Fce 31 - Výběr 100EUR z účtu v jiné měně)")
    public void func31underLimit100EUR(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 31 UnderLimit100EUR) ----------------");

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction31().MA_AccountNumber(KSNAccounts.CZK_215667013.getValue())
            .EnterFunction31()
            .withdrawAmount("100")
            .authPerson1()
            .fillIdentificationAndSymbolsMini()
            .continueWithPrintAction()
            .dismissPrintWindow()
            .continueWithSaveAction()
            .checkFunctionIsDone()
            .logOut();

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

}
