package cz.moneta.test.regression.data.api.ufobanka;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.tasks.BankaTasks;
import cz.moneta.test.dsl.ufo.banka.tasks.accountenums.CurrentAccountsEnum;
import cz.moneta.test.dsl.util.data.client.NonClient;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.AuthSupport;
import org.jooq.Record;
import org.jooq.Result;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;

import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.CLIENT_CIF_STORE_KEY;
import static cz.moneta.test.dsl.util.credentials.Keys.ufo.banka.banker;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "UFOBanka - action with Bank Api channel")
public class BankApiChannelUfoBanka {

    private static final String BANKAPI_LIMIT_EDIT = "60000";
    private static final String BANKAPI_LIMIT_NEW = "50000";

    @Deprecated
    @Disabled("Obsolete, to be reviewed.")
    @TestCase(name = "Create new customer and create bank api channel", environments = {TST1})
    @JiraTestCase(id = "AO-T435")
    public void tc_create_bank_api_channel_via_ufobanka(Harness harness) {

        BankaTasks tasks = harness.tasks().ufo().banka();
        NonClient nonClient = harness.data().newNonClient();
        String bankerUsername = AuthSupport.getCredentials(banker, harness).getUsername();

        String limit = harness.withUfo()
                .openLoginPage()
                .then(tasks.login().asBanker())
                .then(tasks.login().turnSignpadOff())
                .then(tasks.newClient().create(nonClient, bankerUsername))
                .then(tasks.newPackagedProductTasks().ibWithMobileKeyAndCurrentAccount(nonClient, CurrentAccountsEnum.GENIUS_FREE_FLEXI))
                .clickInternetBankWithMobileKey()
                .activationBankApiChannel()
                .acceptAlert()
                .clickGenerateLater()
                .onMainClientPage()
                .checkProductActive("Bank API; Aktivní")
                .clickBankApi()
                .getLimit();

        Assertions.assertEquals(limit, BANKAPI_LIMIT_NEW);

        Result<Record> records = harness.withUdebs()
                .clientPaymentsLimits()
                .getLimitsAmount(harness.get(CLIENT_CIF_STORE_KEY));

        limit = records.getValue(0, "LIMIT").toString();

        Assertions.assertEquals(limit, BANKAPI_LIMIT_NEW);
    }

    @Deprecated
    @Disabled("Obsolete, to be reviewed.")
    @TestCase(name = "Edit bank api channel, setting limit", environments = {TST1})
    @JiraTestCase(id = "AO-T436")
    public void tc_edit_bank_api_channel_via_ufobanka(Harness harness) {

        BankaTasks tasks = harness.tasks().ufo().banka();
        NonClient nonClient = harness.data().newNonClient();
        String bankerUsername = AuthSupport.getCredentials(banker, harness).getUsername();

        String limit = harness.withUfo()
                .openLoginPage()
                .then(tasks.login().asBanker())
                .then(tasks.login().turnSignpadOff())
                .then(tasks.newClient().create(nonClient, bankerUsername))
                .then(tasks.newPackagedProductTasks().ibWithMobileKeyAndCurrentAccount(nonClient, CurrentAccountsEnum.GENIUS_FREE_FLEXI))
                .clickInternetBankWithMobileKey()
                .activationBankApiChannel()
                .acceptAlert()
                .clickGenerateLater()
                .onMainClientPage()
                .clickBankApi()
                .editBankApiChannel()
                .fillDailyLimit(BANKAPI_LIMIT_EDIT)
                .saveLimitBanApi()
                .clickGenerateLater()
                .onOnlineChannelsPage()
                .getLimit();

        Assertions.assertEquals(limit, BANKAPI_LIMIT_EDIT);

        Result<Record> records = harness.withUdebs()
                .clientPaymentsLimits()
                .getLimitsAmount(harness.get(CLIENT_CIF_STORE_KEY));

        limit = records.getValue(0, "LIMIT").toString();

        Assertions.assertEquals(limit, BANKAPI_LIMIT_EDIT);
    }

    @Deprecated
    @Disabled("Obsolete, to be reviewed.")
    @TestCase(name = "Cancel bank api channel with remove IB channel", environments = {TST1})
    public void tc_cancel_bank_api_channel_via_ufobanka(Harness harness) {

        BankaTasks tasks = harness.tasks().ufo().banka();
        NonClient nonClient = harness.data().newNonClient();
        String bankerUsername = AuthSupport.getCredentials(banker, harness).getUsername();

        harness.withUfo()
                .openLoginPage()
                .then(tasks.login().asBanker())
                .then(tasks.login().turnSignpadOff())
                .then(tasks.newClient().create(nonClient, bankerUsername))
                .then(tasks.newPackagedProductTasks().ibWithMobileKeyAndCurrentAccount(nonClient, CurrentAccountsEnum.GENIUS_FREE_FLEXI))
                .clickInternetBankWithMobileKey()
                .activationBankApiChannel()
                .acceptAlert()
                .clickGenerateLater()
                .onMainClientPage()
                .clickBankApi()
                .editIbPasswordMkChannel()
                .cancelInternetBankChannel()
                .acceptAlert()
                .continueToPrint()
                .clickPrintEmpowermentNow()
                .onClientFinalSignatureConfirmationPage()
                .clickClientAgreedAndSignedAllInfo()
                .returnHKO();

        Result<Record> records = harness.withUdebs()
                .clientPaymentsLimits()
                .getLimitsAmount(harness.get(CLIENT_CIF_STORE_KEY));

        Assertions.assertEquals(records.size(), 0);
    }
}