package cz.moneta.test.dsl.hypos.pages.contract;

import cz.moneta.test.dsl.hypos.components.Menu;
import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.dsl.hypos.pages.hypokom.HypokomSearchPage;
import cz.moneta.test.dsl.util.data.hypos.HyposContract;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.hypos.HyposEndpoint;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.hypos.pages.contract.NewContractPage.PAGE_TITLE_XPATH;

@Wait(PAGE_TITLE_XPATH)
public interface NewContractPage extends HyposPageFlow<HypokomSearchPage>, Menu, StoreAccessor {
    String PAGE_TITLE_XPATH = "//h1[text()='Nový obchod']";
    String CLIENT_AGREEMENT_XPATH = "//div[@id='client-%s']";
    String AGREEMENT_MARKETING_IMG_XPATH = CLIENT_AGREEMENT_XPATH + "//img[@id='img-MarketingByAllChannels']";
    String AGREEMENT_CHANNELS_IMG_XPATH = CLIENT_AGREEMENT_XPATH + "//img[@id='img-CommBankSecretByUnsecured']";
    String AGREEMENT_MESSAGING_IMG_XPATH = CLIENT_AGREEMENT_XPATH + "//img[@id='img-InstantMessagingByAllPlatforms']";
    String ARES_AND_JUSTICE_BUTTON_XPATH = "//input[@value='ARES a JUSTICE']";
    String ESTABLISH_BUTTON_XPATH = "//input[@value='Založit']";

    @CustomAction
    default NewContractPage checkAgreements(HyposContract hyposContract) {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        for (int i = 0; i < hyposContract.getClients().size(); i++) {
            String client = String.valueOf(i + 1);
            endpoint.click(() -> String.format(AGREEMENT_MARKETING_IMG_XPATH, client));
            endpoint.click(() -> String.format(AGREEMENT_CHANNELS_IMG_XPATH, client));
            endpoint.click(() -> String.format(AGREEMENT_MESSAGING_IMG_XPATH, client));
        }
        return null;
    }

    @Click(ARES_AND_JUSTICE_BUTTON_XPATH)
    NewContractPage clickAresAndJustice();

    @Click(ESTABLISH_BUTTON_XPATH)
    EditContinuePage clickEstablishContract();
}