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.kasanova.components.enums.KSNPersons;
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.KSNFunction12Test;
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 33) Výběr v měně účtu, VK")
public class KSNFunction33Test {

    private KSNFunction12Test function12test;
    private boolean doOpposite;
    private final String VK_CZK_2110_3226830764 = "2110-3226830764";

    @Order(1)
    @JiraTestCase(id = "PAY-T1394")
    @TestCase(name = "(Fce 33 - podlimit)")
    public void func33underLimit(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 33 UnderLimit) ----------------");

        if (doOpposite == true) {
            function12test = new KSNFunction12Test();
            function12test.underLimitWithDispo(harness, banker, false);
        }

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection3()
                .KSNFunction33()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction33()
                .withdrawAmount("408")
                .kasanovaDialogClickOK()
                .checkPaycheck(400.0)
                .authPerson(KSNPersons.LEOS_CHALUPA.getValue())
                .fillIdentificationAndSymbolsForDepositbook()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

        harness.log("---------------- END TEST (FUNCTION 33 UnderLimit) ----------------");
    }

    @Order(2)
    @JiraTestCase(id = "PAY-T1395")
    @TestCase(name = "(Fce 33 - mezilimit)")
    public void func33middleLimit(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 33 MiddleLimit) ----------------");

        if (doOpposite == true) {
            function12test = new KSNFunction12Test();
            function12test.middleLimitWithDispo(harness, banker, false);
        }

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection3()
                .KSNFunction33()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction33()
                .withdrawAmount("51020")
                .kasanovaDialogClickOK()
                .checkPaycheck(50000.0)
                .authPerson(KSNPersons.LEOS_CHALUPA.getValue())
                .fillIdentificationAndSymbolsForDepositbook()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

        harness.log("---------------- END TEST (FUNCTION 33 MiddleLimit) ----------------");
    }

    @Order(3)
    @JiraTestCase(id = "PAY-T1396")
    @TestCase(name = "(Fce 33 - nadlimit)")
    public void func33overLimit(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 33 OverLimit) ----------------");

        if (doOpposite == true) {
            function12test = new KSNFunction12Test();
            function12test.overLimitWithDispo(harness, banker, verifyBanker, false);
        }

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection3()
                .KSNFunction33()
                .MA_AccountNumber(KSNAccounts.VK_CZK_4170859.getValue())
                .enterFunction33()
                .withdrawAmount("510204")
                .waitSec()
                .kasanovaDialogClickOK()
                .checkPaycheck(500000.0)
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_1.getValue())
                .authPerson(KSNPersons.LEOS_CHALUPA.getValue())
                .fillIdentificationAndSymbolsForDepositbook()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .doVerification(harness, "510204", KSNAccounts.VK_CZK_4170859.getValue(), verifyBanker)
                .checkFunctionIsDone()
                .logOut();

        harness.log("---------------- END TEST (FUNCTION 33 OverLimit) ----------------");
    }

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

        harness.withKasanova()
            .openLoginPage()
            .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
            .KSNSection3()
            .KSNFunction33()
            .MA_AccountNumber(VK_CZK_2110_3226830764)
            .enterFunction33()
            .backToMainMenu()
            .logOut();
        harness.log("---------------- END TEST (FUNCTION 33 ExternalAccForm) ----------------");
    }

}
