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

import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.Order;
import cz.moneta.test.dsl.Harness;
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;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@NonConcurrentTestScenario(name = "(Fce 62) Směnárna, Prodej valut bankou")
public class KSNFunction62Test {

    KSNFunction61Test function61test;
    private boolean doOpposite;

    @Order(1)
    @JiraTestCase(id = "PAY-T1695")
    @TestCase(name = "(Fce 62 - podlimit)")
    public void func62underLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        underLimit(harness, banker, doOpposite);
    }
    public void underLimit(Harness harness, Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 62 UnderLimit) ----------------");

        if (doOpposite) {
            function61test = new KSNFunction61Test();
            function61test.underLimit(harness, banker, false);
        }

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection6()
                .KSNFunction62()
                .enterFunction62()
                .vyplataAmount("5")
                .fillCoinsplitTable()
                .fillIdentificationAndSymbolsSmenaShort()
                .continueWithPrintAction()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();
        
        harness.log("---------------- END TEST (FUNCTION 62 UnderLimit) ----------------");
    }

    @Order(2)
    @JiraTestCase(id = "PAY-T1696")
    @TestCase(name = "(Fce 62 - mezilimit)")
    public void func62middleLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        middleLimit(harness, banker, doOpposite);
    }
    public void middleLimit(Harness harness, Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 62 MiddleLimit) ----------------");

        if (doOpposite) {
            function61test = new KSNFunction61Test();
            function61test.middleLimit(harness, banker, false);
        }

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection6()
                .KSNFunction62()
                .enterFunction62()
                .vyplataAmount("1600")
                .kasanovaDialogClickOK()
                .fillCoinsplitTable()
                .fillIdentificationAndSymbolsSmenaLong()
                .clickPrintInfo()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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

    @Order(3)
    @JiraTestCase(id = "PAY-T1697")
    @TestCase(name = "(Fce 62 - nadlimit)")
    public void func62overLimit(Harness harness, @Key(kasanova.banker) Credentials banker) {
        doOpposite = Boolean.parseBoolean(harness.getConfig("kasanova-config.doOpposite"));
        overLimit(harness, banker, doOpposite);
    }
    public void overLimit(Harness harness, Credentials banker, boolean doOpposite) {
        harness.log("---------------- START TEST (FUNCTION 62 OverLimit) ----------------");

        if (doOpposite) {
            function61test = new KSNFunction61Test();
            function61test.overLimit(harness, banker, false);
        }

        harness.withKasanova()
                .openLoginPage()
                .then(harness.tasks().kasanova().loginWithUserAndPassword(banker))
                .KSNSection6()
                .KSNFunction62()
                .enterFunction62()
                .vyplataAmount("18000")
                .kasanovaDialogClickOK()
                .originePurpose(KSNOriginDeposit.PUVOD_VKLADU_7.getValue())
                .originePurpose2(KSNOriginDeposit.PUVOD_VKLADU_10.getValue())
                .fillCoinsplitTable()
                .fillIdentificationAndSymbolsSmenaLong()
                .clickPrintInfo()
                .kasanovaDialogClickOK()
                .dismissPrintWindow()
                .kasanovaDialogClickOK()
                .continueWithPrintAction()
                .kasanovaDialogClickYes()
                .dismissPrintWindow()
                .continueWithSaveAction()
                .checkFunctionIsDone()
                .logOut();

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