package cz.moneta.test.regression.backoffice.ufooperations.regressionsbbo;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.search.SearchBy;
import cz.moneta.test.dsl.util.DateUtils;
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.ParameterizedTestCase;
import cz.moneta.test.harness.annotations.TestScenarioWithOrder;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.params.provider.ValueSource;

import static cz.moneta.test.dsl.util.task.ufo.cb.CommercialTasks.JIRA_COMMENT_STORE_KEY;
import static cz.moneta.test.harness.annotations.Environment.PPE;

@TestScenarioWithOrder(name = "Print Templates Brki")
public class PrintTemplatesBrki {

    String department = "OPERATIONS_PAYMENTS_ZAKLAD";
    String category = "BRKI";
    String CIF;

    @Order(1)
    @ParameterizedTestCase(name = "Print template BRKI Another Address", environments = {PPE})
    @ValueSource(strings = {
            "Dodání OP BRKI"
    })
    @JiraTestCase(id = "BOC-T8689")
    public void printTemplatesBrkiAnotherAddress(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000064103";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.store("PRINT_NAME", printName);
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .clickRcRadio()
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .clickPrintLettersWithCif()
                .selectDepartment(department)
                .selectCategory(category)
                .selectTemplate(printName)
                .selectGenderIfVisible()
                .clickAnotherAddress()
                .fillNameInput("David Novák")
                .fillStreetInput("Dlouhá")
                .fillBuildingNumberInput("928")
                .fillStreetNumberInput("1")
                .fillCityInput("Praha")
                .fillPostalCodeInput("11000")
                .clickPrintWithAnotherAddress()
                .clickAddress()
                .clickPrint()
                .clickSaveToDmsIfNotChecked()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName(printName)
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(2)
    @ParameterizedTestCase(name = "Print template BRKI DMS", environments = {PPE})
    @ValueSource(strings = {
            "Dodání OP BRKI"
    })
    @JiraTestCase(id = "BOC-T8665")
    public void printTemplatesBrkiDms(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000003205";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.store("PRINT_NAME", printName);
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .then(operationsTasksTasks.printTemplateTasks().createPrintTemplateWithCif(CIF, department, category, printName))
                .clickSaveToDmsIfNotChecked()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName(printName)
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(3)
    @ParameterizedTestCase(name = "Print template BRKI DOPIS", environments = {PPE})
    @ValueSource(strings = {
            "Dodání OP BRKI"
    })
    @JiraTestCase(id = "BOC-T8686")
    public void printTemplatesBrkiLetter(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000037180";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.store("PRINT_NAME", printName);
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .then(operationsTasksTasks.printTemplateTasks().createPrintTemplateWithCif(CIF, department, category, printName))
                .clickSaveToEts()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName(printName)
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(4)
    @ParameterizedTestCase(name = "Print template BRKI IB", environments = {PPE})
    @ValueSource(strings = {
            "Dodání OP BRKI"
    })
    @JiraTestCase(id = "BOC-T8687")
    public void printTemplatesBrkiIb(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000233806";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.store("PRINT_NAME", printName);
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .then(operationsTasksTasks.printTemplateTasks().createPrintTemplateWithCif(CIF, department, category, printName))
                .clickSaveToIbIfNotChecked()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName(printName)
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(5)
    @ParameterizedTestCase(name = "Print template BRKI Interactive", environments = {PPE})
    @ValueSource(strings = {
            "Informace BRKI",
            "Potvrzení BRKI",
    })
    @JiraTestCase(id = "BOC-T8703")
    public void printTemplatesBrkiInteractive(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000011599";
        String title = "Ondřej Mysl";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.store("PRINT_NAME", printName);
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .clickPrintLettersWithCif()
                .then(operationsTasksTasks.printTemplateTasks().createPrintTemplateInteractive(department, category, printName, title));
    }

    @Order(6)
    @ParameterizedTestCase(name = "Print template BRKI LOCAL", environments = {PPE})
    @ValueSource(strings = {
            "Dodání OP BRKI"
    })
    @JiraTestCase(id = "BOC-T8685")
    public void printTemplatesBrkiLocal(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000069092";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.store("PRINT_NAME", printName);
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .then(operationsTasksTasks.printTemplateTasks().createPrintTemplateWithCif(CIF, department, category, printName))
                .clickSaveToLocal()
                .clickSendAndClosePrintWindow();
    }

    @AfterEach
    protected void teardown(Harness harness) {
        harness.store(JIRA_COMMENT_STORE_KEY,
                "\nUFO Session ID: " + harness.get("reports.tmfj.execution.commentufosessionid") +
                        "\nNázev dopisu: " + harness.get("PRINT_NAME") +
                        "\nCIF: " + CIF);
    }
}