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

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.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import cz.moneta.test.harness.support.auth.Key;
import org.junit.jupiter.api.BeforeAll;

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

@TestScenario(name = "Sending forms")
public class SendingForms {
    private OperationsTasks operationsTasks;

    private String rcOfExistingClient;

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

    @TestCase(name = "Sending manuals", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2148")
    public void sendingManuals(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .assertClientRc(rcOfExistingClient)
                .clickSendingOffers()
                .assertOffers()
                .checkRecordsOfDocumentsForSending()
                .checkSelectedDocumentsForSending("Vybrané dokumenty k odeslání")
                .checkSendButton()
                .selectSegmentOfClient(2)
                .selectProductGroup("Půjčky")
                .clickSearch()
                .clickDocumentDetailAndCheck()
                .closeDocumentWindowAndSwitchToCurrentWindow()
                .clickAddFirstDocument()
                .typeIntoEmailInput("jakub.havelka@moneta.cz")
                .selectContactForClient("Pojištění - 224 445 666")
                .clickSend()
                .assertStatusBarContent("Manuály byly odeslány")
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveTime())
                .assertFirstRequirementDescription("Prodej - Zaslán leták")
                .scrollToSendingOffersManuals()
                .clickSendingOffers()
                .clickAddFirstDocument()
                .clickAddSecondDocument()
                .typeIntoEmailInput("jakub.havelka@moneta.cz")
                .selectContactForClient("Akviziční linka -  224 446 543")
                .clickSend()
                .assertStatusBarContent("Manuály byly odeslány")
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveTime())
                .assertFirstRequirementDescription("Prodej - Zaslán leták");
    }
}
