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.TestCase;
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 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 = "Manual letter")
public class ManualLetters {

    String CIF;

    @Order(1)
    @TestCase(name = "Manual Letter Dms", environments = {PPE})
    @JiraTestCase(id = "BOC-T8690")
    public void manualLettersDms(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000002731";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .then(operationsTasksTasks.printTemplateTasks().createManualLetter())
                .clickSaveToDmsIfNotChecked()
                .clickSend()
                .onClientDocuments()
                .assertPrintName("Sdělení klientovi")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(2)
    @TestCase(name = "Manual Letter Dopis", environments = {PPE})
    @JiraTestCase(id = "BOC-T8733")
    public void manualLettersLetter(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000019034";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .then(operationsTasksTasks.printTemplateTasks().createManualLetter())
                .clickSaveToEts()
                .clickSend()
                .onClientDocuments()
                .assertPrintName("Sdělení klientovi")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(3)
    @TestCase(name = "Manual Letter IB", environments = {PPE})
    @JiraTestCase(id = "BOC-T8732")
    public void manualLettersIb(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000092508";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .then(operationsTasksTasks.printTemplateTasks().createManualLetter())
                .clickSaveToIbIfNotChecked()
                .clickSend()
                .onClientDocuments()
                .assertPrintName("Sdělení klientovi")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(4)
    @TestCase(name = "Manual Letter Local", environments = {PPE})
    @JiraTestCase(id = "BOC-T8731")
    public void manualLettersLocal(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000003128";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .then(operationsTasksTasks.printTemplateTasks().createManualLetter())
                .clickSaveToEts()
                .clickSend()
                .onClientDocuments()
                .assertPrintName("Sdělení klientovi")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

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