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

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.*;
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 java.time.LocalDate;

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

@TestScenarioWithOrder(name = "SharingContacts")
public class ArrangementXkom {

    private OperationsTasks operationsTasks;
    private String rcOfExistingClient;
    private String numberOfAccount;

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

    @Order(1)
    @TestCase(name = "Arrangement X-Coms - Car")
    @JiraTestCase(id = "CC-T2186")
    public void arrangementXcomsCar(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickCar()
                .checkName("Arnold")
                .checkSurname("Stejnojmený")
                .checkEmail("ilods@moneta.cz")
                .fillTelephone("720855895")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .checkVillage("Praha 2")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .checkInactiveAvailabilityHours()
                .clickSendAndCheckExpectedErrorAlert()
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .clickConsent101()
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Prodej - X-KOM");
    }

    @Order(2)
    @TestCase(name = "Arrangement X-Coms - Future opportunities")
    @JiraTestCase(id = "CC-T2188")
    public void arrangementXcomsFutureOpportunities(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickFutureOpportunities()
                .selectInterestIn("Hypotéky")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkdayAfterDate(LocalDate.now().plusMonths(1)), "d.M.yyyy"))
                .fillNote("Jedná se o TEST, není třeba řešit")
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Prodej - Budoucí příležitost - Hypotéky");
    }

    @Order(3)
    @TestCase(name = "Arrangement X-Coms - Mortgages")
    @JiraTestCase(id = "CC-T2189")
    public void arrangementXcomsMortgages(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickMortgages()
                .checkName("Arnold")
                .checkSurname("Stejnojmený")
                .checkBirthNumber("9206177398")
                .fillPhone("720855895")
                .checkEmail("ilods@moneta.cz")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .checkVillage("Praha 2")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .fillAvailabilityTimeHour("13")
                .fillAvailabilityTimeMinute("30")
                .selectContactSource("Call Centrum")
                .fillAmount("200000")
                .clickConsent101()
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Prodej - X-KOM");
    }

    @Order(4)
    @TestCase(name = "Arrangement X-Coms - Retention")
    @JiraTestCase(id = "CC-T2190")
    public void arrangementXcomsRetention(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickRetention()
                .selectProduct(numberOfAccount )
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .fillAvailabilityTimeHour("13")
                .fillAvailabilityTimeMinute("30")
                .fillTelephone("720855895")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .clickCallAsPriority()
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Telemarketing - Retence - Požadavek z Call Centra");
    }

    @Order(5)
    @TestCase(name = "Arrangement X-Coms - SME")
    @JiraTestCase(id = "CC-T2191")
    public void arrangementXcomsSME(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickSME()
                .checkActiveIco()
                .checkName("Arnold")
                .checkSurname("Stejnojmený")
                .checkNameOfCompany("Ing. Arnold Stejnojmený")
                .fillMobile("720855895")
                .checkEmail("ilods@moneta.cz")
                .selectInterestIn("Úvěrový produkt")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .checkVillage("Praha 2")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .checkInactiveAvailabilityHours()
                .selectContactSource("Call Centrum")
                .clickSendSMSAndDocuments()
                .clickConsent101()
                .clickSend();
    }

    @Order(6)
    @TestCase(name = "Arrangement X-Coms - Ecomm")
    @JiraTestCase(id = "CC-T2192")
    public void arrangementXcomsEcomm(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickEcomm()
                .checkName("Arnold")
                .checkSurname("Stejnojmený")
                .selectReasonOfHandover("Předáno chat")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .checkInactiveAvailabilityHours()
                .fillTelephone("720855895")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .clickPriorityCall()
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum Banka - Xkom - Ecomm");
    }

    @Order(7)
    @TestCase(name = "Arrangement X-Coms - Sell")
    @JiraTestCase(id = "CC-T2193")
    public void arrangementXcomsSell(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickSell()
                .checkName("Arnold")
                .checkSurname("Stejnojmený")
                .checkBirthNumber("9206177398")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .fillAvailabilityTimeHour("14")
                .fillAvailabilityTimeMinute("00")
                .fillTelephone("720855895")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum banka - Xkom - Prodej");
    }

    @Order(8)
    @TestCase(name = "Arrangement X-Coms - Acquisition")
    @JiraTestCase(id = "CC-T2194")
    public void arrangementXcomsAcquisition(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickAcquisition()
                .fillName("Arnold")
                .fillSurname("Stejnojmený")
                .fillDate(DateUtils.getDateWithFormat(DateUtils.getNextWorkday(), "d.M.yyyy"))
                .fillAvailabilityTimeHour("13")
                .fillAvailabilityTimeMinute("30")
                .fillTelephone("720855895")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum Banka - Xkom - akvizice");
    }

    @Order(9)
    @Defect(value = "Defekt na TST1 - DFM-40010", environments = {TST1})
    @TestCase(name = "Arrangement X-Coms - Other")
    @JiraTestCase(id = "CC-T2195")
    public void arrangementXcomsOther(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {
        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .then(operationsTasks.clientDetails().stepsOnContactForwarding(rcOfExistingClient))
                .clickOther()
                .selectNameOfCampaign("test1 - XKOM-UFO_OPS")
                .checkBirthNumber("9206177398")
                .checkName("Arnold")
                .checkSurname("Stejnojmený")
                .fillMobile("720855895")
                .checkEmail("ilods@moneta.cz")
                .checkVillage("Praha 2")
                .fillNote("Jedná se o TEST, není třeba řešit")
                .fillAvailabilityTimeHour("13")
                .fillAvailabilityTimeMinute("00")
                .selectSourceOfContact("Call Centrum")
                .selectProductToCancel("Vyberte produkt ke zrušení")
                .selectTypeOfWrittenRequest("Obecné Info")
                .selectReasonOfHandover("Předáno chat")
                .selectInterestOf("Běžné účty")
                .clickConsent101()
                .clickSendSmsAndDocumentations()
                .clickSend()
                .then(operationsTasks.clientDetails().assertFirstRequirementSolveDate())
                .assertFirstRequirementDescription("Call centrum Banka - Xkom");
    }
}
