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 = "Change address")
class ChangeAddress {

    String CIF;

    @Order(1)
    @TestCase(name = "Change address DMS", environments = {PPE})
    @JiraTestCase(id = "BOC-T8770")
    public void changeAddressDms(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000085272";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .fillStreet("Vyskočilova")
                .clickSaveCheckAddress()
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeToWrongAddress())
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeAddressByCondition())
                .clickCheckData()
                .onPrintTemplatePage()
                .clickSaveToDMS()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName("Změna kontaktních údajů - změnový dokument")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(2)
    @TestCase(name = "Change address Dopis", environments = {PPE})
    @JiraTestCase(id = "BOC-T8773")
    public void changeAddressLetter(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "9001123454";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .fillStreet("Vyskočilova")
                .clickSaveCheckAddress()
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeToWrongAddress())
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeAddressByCondition())
                .clickCheckData()
                .onPrintTemplatePage()
                .clickSaveToEts()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName("Změna kontaktních údajů - změnový dokument")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(3)
    @TestCase(name = "Change address Ib", environments = {PPE})
    @JiraTestCase(id = "BOC-T8772")
    public void changeAddressIb(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000233809";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .fillStreet("Vyskočilova")
                .clickSaveCheckAddress()
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeToWrongAddress())
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeAddressByCondition())
                .clickCheckData()
                .onPrintTemplatePage()
                .clickSaveToIbIfNotChecked()
                .clickSend()
                .onClientDetailPage()
                .clickCorrespondence()
                .assertPrintName("Změna kontaktních údajů - změnový dokument")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(4)
    @TestCase(name = "Change address Local", environments = {PPE})
    @JiraTestCase(id = "BOC-T8774")
    public void changeAddressLocal(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.CIF = "3000050260";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(CIF)
                .searchBy(SearchBy.CIF)
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .fillStreet("Vyskočilova")
                .clickSaveCheckAddress()
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeToWrongAddress())
                .then(harness.tasks().ufo().operations().changeContactAddressTasks().changeAddressByCondition())
                .clickCheckData()
                .onPrintTemplatePage()
                .clickSaveToLocal()
                .clickSendAndClosePrintWindow();
    }

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