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

import cz.moneta.test.dsl.Harness;
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.Disabled;
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;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenarioWithOrder(name = "RevokePersonalDataConsents")
public class RevokePersonalDataConsents {

    String revoked = "odvolaný";
    String valid = "platný";
    String birthNumber;

    @Order(1)
    @TestCase(name = "Marketing Consents", environments = {PPE, TST1})
    @JiraTestCase(id = "BOC-T8858")
    public void marketingConsents(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.birthNumber = "6608120717";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(birthNumber)
                .clickRcRadio()
                .clickSearchClient()
                .onClientDetailsPage()
                .clickClientConsents()
                .clickGiveAllConsents()
                .acceptAlert()
                .checkEmailMMBConsents(valid)
                .checkPostMMBConsents(valid)
                .checkSmsMMBConsents(valid)
                .checkTelephoneMMBConsents(valid)
                .checkIbSbMMBConsents(valid)
                .checkSurveysMMBConsents(valid)
                .clickRevokeEmail()
                .checkEmailMMBConsents(revoked)
                .clickRevokePostConsent()
                .checkPostMMBConsents(revoked)
                .clickRevokeSmsConsent()
                .checkSmsMMBConsents(revoked)
                .clickRevokeTelephoneConsent()
                .checkTelephoneMMBConsents(revoked)
                .clickRevokeIbSbConsent()
                .checkIbSbMMBConsents(revoked)
                .clickRevokeSurveysConsent()
                .checkSurveysMMBConsents(revoked)
                .selectTypeOfPrint(2)
                .clickGeneratePrint()
                .clickSaveToEts()
                .clickSendButton()
                .onClientConsentsPage()
                .clickCorrespondence()
                .assertPrintName("Odvolání MKT – kanály")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"));
    }

    @Order(2)
    @TestCase(name = "Another Consents", environments = {PPE, TST1})
    @JiraTestCase(id = "BOC-T8873")
    public void anotherConsents(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        this.birthNumber = "7401185044";
        OperationsTasks operationsTasksTasks = harness.tasks().ufo().operations();

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasksTasks.login().withCredentials(credentials))
                .fillSearchInput(birthNumber)
                .clickRcRadio()
                .clickSearchClient()
                .onClientDetailsPage()
                .clickClientConsents()
                .clickGiveUnencryptedCommunicationConsents()
                .clickGiveInstantMessagingConsents()
                .checkUnencryptedCommunicationMMBConsents(valid)
                .checkWhatsappMMBConsents(valid)
                .checkOtherChannelsMMBConsents(valid)
                .clickRevokeUnencryptedCommunication()
                .checkUnencryptedCommunicationMMBConsents(revoked)
                .clickRevokeWhatsapp()
                .checkWhatsappMMBConsents(revoked)
                .clickRevokeOtherChannels()
                .checkOtherChannelsMMBConsents(revoked)
                .selectTypeOfPrint(5)
                .clickGeneratePrint()
                .clickSaveToEts()
                .clickSendButton()
                .onClientConsentsPage()
                .selectTypeOfPrint(11)
                .clickGeneratePrint()
                .clickSaveToEts()
                .clickSendButton()
                .onClientConsentsPage()
                .clickCorrespondence()
                .assertPrintName("Odvolání instant messaging - kanály")
                .assertDate(DateUtils.getFormattedTodayDate("d.M.yyyy"))
                .assertSecondPrintName("Odvolání Nešif.komunikace")
                .assertSecondDate(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", true) +
                        "\nRČ: " + birthNumber);
    }
}