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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.operations.recorder.RecorderNameOfGroup;
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 = "UFOCRC")
public class UfoCrcTests {
    private OperationsTasks operationsTasks;
    private String rcOfExistingClient;

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

    @TestCase(name = "UFOCRC - ClientLoading", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2112")
    public void ufoCrcClientLoading(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .copyRcOfClientToClipboard()
                .clickRecorder()
                .clickInsertSubjectFromClipboard()
                .clickBirthNumberInSubject()
                .clickLoadSubjectArrow()
                .checkNameOfClient("Automaticky Nebrat")
                .closeRecorderWindow()
                .onClientSearchPage()
                .clickRecorder()
                .clickBirthNumberInSubject()
                .fillSearchSubjectInput(rcOfExistingClient)
                .clickLoadSubjectArrow()
                .checkNameOfClient("Automaticky Nebrat")
                .checkPresentOfRequirement()
                .closeRecorderWindow()
                .onClientSearchPage()
                .copyRcOfClientToClipboard()
                .clickSearchClient()
                .onClientDetailsPage()
                .copyCifNumberToClipboard()
                .clickRecorder()
                .fillSearchSubjectInput("")
                .clickInsertSubjectFromClipboard()
                .clickCifInSubject()
                .clickLoadSubjectArrow()
                .checkNameOfClient("Automaticky Nebrat")
                .checkPresentOfRequirement()
                .closeRecorderWindow()
                .onClientDetailPage()
                .clickHomePage()
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .clickLoans()
                .copyLoansNumberToClipboard()
                .clickRecorder()
                .insertNumberOfContract()
                .checkNameOfClient("Automaticky Nebrat")
                .clickLoadSubjectArrow()
                .checkNumberOfContractInRequirement();
    }

    @TestCase(name = "UFOCRC - ClientLoadingAndCheckProductsTree", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2128")
    public void ufoCrcClientLoadingAndCheckProductsTree(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .copyRcOfClientToClipboard()
                .clickSearchClient()
                .onClientDetailsPage()
                .clickRecorder()
                .clickInsertSubjectFromClipboard()
                .clickBirthNumberInSubject()
                .clickLoadSubjectArrow()
                .checkNameOfClient("Automaticky Nebrat")
                .clickDetailOfCrcRequirement()
                .checkDescriptionOfRequirementDetail()
                .clickCloseDetailCrcRequirement()
                .then(harness.tasks().ufo().operations().recorder().openCategories(RecorderNameOfGroup.MMB, RecorderNameOfGroup.OM_RETAIL))
                .openItemInTreeMenu("FRAUD")
                .checkSolutionsDiv();
    }
}
