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.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 = "Change of clients contact details")
public class ChangeOfClientsContactDetails {

    private String rcOfExistingClient;
    private OperationsTasks operationsTasks;

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

    @TestCase(name = "Change of clients contact details - address", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2122")
    public void changeOfClientsContactDetails_Address(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .clickUseProductOnSecondPlace()
                .fillStreet("Rudná")
                .fillDescriptionNumber("3114")
                .fillPostalCode("70030")
                .fillDistrictNumber("Zábřeh")
                .fillCity("Ostrava")
                .selectCountry(52)
                .clickSaveAddress()
                .clickChooseAddress()
                .clickSaveAddress()
                .clickCheckData()
                .onAmortizationPage()
                .checkIfIBSBIsChecked()
                .checkAmortizationLabel("Změna kontaktních údajů - změnový dokument")
                .clickSendButton()
                .onClientDetailPage()
                .menuClickChangeContactData()
                .checkAddressDiv2("Rudná 3114/114, 700 30 Ostrava, Zábřeh, Česká republika,")
                .clickUseProductOnSecondPlace()
                .fillStreet("Na Rovince")
                .fillDescriptionNumber("872")
                .fillPostalCode("72000")
                .fillDistrictNumber("Hrabová")
                .fillCity("Ostrava")
                .clickSaveAddress()
                .clickChooseAddress()
                .clickSaveAddress()
                .checkAddressDiv2("Na Rovince 872/, 720 00 Ostrava, Hrabová, Česká republika,")
                .clickCheckData()
                .onAmortizationPage()
                .checkIfIBSBIsChecked()
                .checkAmortizationLabel("Změna kontaktních údajů - změnový dokument")
                .clickSendButton()
                .onClientDetailPage()
                .clickDemand()
                .clickRefreshRequirementButton()
                .checkDemandDescriptionFirstRow("Call centrum Banka - Aktualizace údajů - Provedeno");
    }

    @TestCase(name = "Change of clients contact details - email", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2123")
    public void changeOfClientsContactDetails_Email(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .clickChangeOnAllProductsEmail()
                .fillEmail("matej.liska@moneta.cz")
                .clickSaveEmail()
                .checkEmailDiv1("matej.liska@moneta.cz")
                .checkEmailDiv2("matej.liska@moneta.cz")
                .clickChangeOnSelectedProductsEmail()
                .clickEmailProductsFirstRow()
                .fillEmail("matej.liska1@moneta.cz")
                .clickSaveEmail()
                .checkEmailDiv1("matej.liska1@moneta.cz")
                .clickCheckData()
                .onClientDetailPage()
                .clickDemand()
                .clickRefreshRequirementButton()
                .checkDemandDescriptionFirstRow("Call centrum Banka - Aktualizace údajů - Provedeno");
    }

    @TestCase(name = "Change of clients contact details - telephone", environments = {PPE, TST1})
    @JiraTestCase(id = "CC-T2124")
    public void changeOfClientsContactDetails_Telephone(Harness harness, @Key(Keys.ufo.banka.banker) Credentials credentials) {

        harness.withUfo()
                .openLoginPage()
                .then(operationsTasks.login().withCredentials(credentials))
                .fillSearchInput(rcOfExistingClient)
                .clickSearchClient()
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .clickChangeOnAllProductsTelephone()
                .fillTelPrefix("420")
                .fillTelephone("111111111")
                .clickSaveTelephone()
                .clickCheckData()
                .onClientDetailPage()
                .fillMenuSearchParameter(rcOfExistingClient)
                .clickSearchArrowButton()
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .checkTelephoneProductsFirstRowDiv("111111111")
                .checkTelephoneProductsSecondRowDiv("111111111")
                .checkTelephoneProductsThirdRowDiv("111111111")
                .checkTelephoneProductsFourthRowDiv("111111111")
                .clickChangeOnSelectedProductsTelephone()
                .clickTelephoneSecondRowCheckbox()
                .clickTelephoneThirdRowCheckbox()
                .fillTelPrefix("420")
                .fillTelephone("734426356")
                .clickSaveTelephone()
                .clickCheckData()
                .onClientDetailPage()
                .fillMenuSearchParameter(rcOfExistingClient)
                .clickSearchArrowButton()
                .onClientDetailsPage()
                .menuClickChangeContactData()
                .checkTelephoneProductsSecondRowDiv("734426356")
                .checkTelephoneProductsThirdRowDiv("734426356");
    }
}
