package cz.moneta.test.regression.backoffice.callcenter.jenkinstests;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.credentials.Keys;
import cz.moneta.test.dsl.util.task.ufo.operations.OperationsTasks;
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.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.BeforeAll;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenario(name = "Confirmation of account managment in UFO OPS")
public class ConfirmationOfAccountManagmentInUfoOps {

    private String rcOfExistingClient;
    private OperationsTasks operationsTasks;

    @BeforeAll
    public void getInfo(Harness harness) {
        operationsTasks = harness.tasks().ufo().operations();
        rcOfExistingClient = harness.getSystemOrConfigValue("cc.confirmationOfAccountClient.rc");
    }

    @TestCase(name = "Confirmation of account management in UFO OPS", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2132")
    public void confirmationOfAccountManagementInUfoOpsCzech(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .clickAccountList()
                .clickConfirmationAboutAccount()
                .clickSend()
                .checkIfIBSBIsChecked()
                .clickSend()
                .onClientDetailPage()
                .assertStatusBarContent("Poplatek byl zaúčtován pod")
                .clickTransactions()
                .then(operationsTasks.transactionsTasks().findAndClickLastTransactionDetailAndCheckValue("300"))
                .checkTransactionDetailAvField("Poplatek za potvrzení")
                .then(operationsTasks.transactionsTasks().comparePostingDateInTransactionDetail())
                .clickBack()
                .clickCorrespondence()
                .assertPrintName("Potvrzení o vedení účtu")
                .checkSendingChannel("Internet Banka/Smart banka")
                .closeCorrespondency()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum Banka - Zaslání dokumentu - vedení účtu");
    }

    @TestCase(name = "Confirmation of account management in UFO OPS", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2133")
    public void confirmationOfAccountManagementInUfoOpsEnglish(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .clickAccountList()
                .clickConfirmationAboutAccount()
                .selectLanguage(1)
                .clickSend()
                .checkIfIBSBIsChecked()
                .clickSend()
                .onClientDetailPage()
                .assertStatusBarContent("Poplatek byl zaúčtován pod")
                .clickTransactions()
                .then(operationsTasks.transactionsTasks().findAndClickLastTransactionDetailAndCheckValue("300"))
                .checkTransactionDetailAvField("Poplatek za potvrzení")
                .then(operationsTasks.transactionsTasks().comparePostingDateInTransactionDetail())
                .clickBack()
                .clickCorrespondence()
                .assertPrintName("Account maintenance confirmation")
                .checkSendingChannel("Internet Banka/Smart banka")
                .closeCorrespondency()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum Banka - Zaslání dokumentu - vedení účtu");
    }

    @TestCase(name = "Confirmation of account management in UFO OPS", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2134")
    public void confirmationOfAccountManagementInUfoOpsWithoutFee(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .clickAccountList()
                .clickConfirmationAboutAccount()
                .selectFee(1)
                .fillReason("chyba na OM")
                .clickSend()
                .checkIfIBSBIsChecked()
                .clickSend()
                .onClientDetailPage()
                .checkStatusBarIsEmpty()
                .clickCorrespondence()
                .assertPrintName("Potvrzení o vedení účtu")
                .checkSendingChannel("Internet Banka/Smart banka")
                .closeCorrespondency()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum Banka - Zaslání dokumentu - vedení účtu");
    }
}
