package cz.moneta.test.regression.backoffice.callcenter.jenkinstests.ccretail.cczakladbanka;

import cz.moneta.test.dsl.Harness;
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.BeforeAll;
import org.junit.jupiter.api.Order;

import static cz.moneta.test.harness.annotations.Environment.PPE;
import static cz.moneta.test.harness.annotations.Environment.TST1;

@TestScenarioWithOrder(name = "Gdpr Tests")
public class GdprTests {
    private OperationsTasks operationsTasks;
    private String rcOfExistingClient;

    @BeforeAll
    public void setupInfo(Harness harness) {
        operationsTasks = harness.tasks().ufo().operations();
        rcOfExistingClient = harness.getSystemOrConfigValue("cc.GdprClient.rc");
    }

    @Order(1)
    @TestCase(name = "Nastavení MKT souhlasu - jednotlivé kanály - email", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2104")
    public void mktConsentSettingsEmail(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.searchClient().byRc(rcOfExistingClient))
                .clickClientConsents()
                .clickRevokeEmail()
                .checkIfMMBTitleIsShowingExpectedText()
                .then(operationsTasks.GdprTasks().checkIfEmailConsentIsChange())
                .clickHistoryConsents()
                .checkIfIsSelectedTodayDate()
                .clickSearchHistory()
                .clickdetailOfListChange()
                .checkTypeOfConsentEmail("Souhlas se zasíláním marketingových nabídek e-mailem (mj. ATM, Sociální sítě, Instant Messaging)")
                .checkConsentsStatusSet("odvolaný")
                .clickRequirement()
                .clickRefreshRequirement()
                .clickDetailOfRequirement()
                .checkNoteDescription("UFO - Souhlasy - Marketing")
                .checkSolutionDescription("UFO - Vyřešeno - Souhlas odvolán")
                .closeRecorderWindow()
                .onClientConsentsPage()
                .clickClientConsents()
                .selectTypeOfPrint(2)
                .clickGeneratePrint()
                .checkIfEmailCheckboxIsDisabled()
                .checkIfIBSBIsChecked()
                .clickSendButton()
                .onClientConsentsPage();
    }

    @Order(2)
    @TestCase(name = "Nastavení MKT souhlasu - jednotlivé kanály - pošta", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2105")
    public void mktConsentSettingsPost(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.searchClient().byRc(rcOfExistingClient))
                .clickClientConsents()
                .clickGiveAllConsents()
                .acceptAlert()
                .clickHistoryConsents()
                .checkIfIsSelectedTodayDate()
                .clickSearchHistory()
                .clickdetailOfListChange()
                .then(operationsTasks.GdprTasks().checkIfTypeOfConsentAreChanged())
                .clickRequirement()
                .clickRefreshRequirement()
                .clickDetailOfRequirement()
                .checkNoteDescription("UFO - Souhlasy - Marketing")
                .checkSolutionDescription("UFO - Vyřešeno - Souhlas udělen")
                .closeRecorderWindow()
                .onClientConsentsPage()
                .clickRevokePostConsent()
                .checkIfMMBTitleIsShowingExpectedText()
                .then(operationsTasks.GdprTasks().checkIfPostConsentIsChange())
                .clickHistoryConsents()
                .checkIfIsSelectedTodayDate()
                .clickSearchHistory()
                .clickdetailOfListChange()
                .checkConsentsStatusSet("odvolaný")
                .clickRequirement()
                .clickRefreshRequirement()
                .clickDetailOfRequirement()
                .checkNoteDescription("UFO - Souhlasy - Marketing")
                .checkSolutionDescription("UFO - Vyřešeno - Souhlas odvolán")
                .closeRecorderWindow()
                .onClientConsentsPage()
                .clickGiveAllConsents()
                .acceptAlert()
                .clickRequirement();
    }
}