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 Ps")
public class PrintTemplatesPs {

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

    @Order(1)
    @ParameterizedTestCase(name = "Print template PS another address", environments = {PPE})
    @ValueSource(strings = {
            "Žádost o doplnění č. úvěru",
            "Žádost o doplnění čísla smlouvy - chybí č. sml.",
            "Žádost o doplnění čísla smlouvy - chybné č. sml."
    })
    @JiraTestCase(id = "BOC-T8668")
    public void printTemplatesPsAnotherAddress(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000027860";
        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 PS DMS", environments = {PPE})
    @ValueSource(strings = {
            "Žádost o doplnění č. úvěru",
            "Žádost o doplnění čísla smlouvy - chybí č. sml.",
            "Žádost o doplnění čísla smlouvy - chybné č. sml."
    })
    @JiraTestCase(id = "BOC-T8664")
    public void printTemplatesPsDms(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "9000599863";
        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 PS DOPIS", environments = {PPE})
    @ValueSource(strings = {
            "Žádost o doplnění č. úvěru",
            "Žádost o doplnění čísla smlouvy - chybí č. sml."
    })
    @JiraTestCase(id = "BOC-T8666")
    public void printTemplatesPsLetter(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000032781";
        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 PS Ib", environments = {PPE})
    @ValueSource(strings = {
            "Žádost o doplnění č. úvěru",
            "Žádost o doplnění čísla smlouvy - chybí č. sml.",
            "Žádost o doplnění čísla smlouvy - chybné č. sml."
    })
    @JiraTestCase(id = "BOC-T8682")
    public void printTemplatesPsIb(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000092508";
        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 PS LOCAL", environments = {PPE})
    @ValueSource(strings = {
            "Žádost o doplnění č. úvěru",
            "Žádost o doplnění čísla smlouvy - chybí č. sml.",
            "Žádost o doplnění čísla smlouvy - chybné č. sml."
    })
    @JiraTestCase(id = "BOC-T8667")
    public void printTemplatesPsLocal(String printName, Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "9001914853";
        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);
    }
}