package cz.moneta.test.dsl.ufo.cb.landing;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

@Wait(value = {SME451_S001_UfoCbLandingPage.SEARCH_LINK, SME451_S001_UfoCbLandingPage.DOCUMENTS_SEARCH_PAGE}, until = Until.VISIBLE)
public interface SME451_S001_UfoCbLandingPage extends WebFlow<SME451_S001_UfoCbLandingPage>, StoreAccessor {

    String BILL_GUARANTOR_LINK = "SME451_S001_I037";
    String COLLATERAL_LINK = "SME451_S001_I011";
    String TASKS_LINK = "SME451_S001_I010";
    String SEARCH_LINK = "SME451_S001_I041";
    String DOCUMENTS_SEARCH_PAGE = "SME451_S001_I009";
    String PRICING_APPROVAL_LINK = "SME451_S001_I020";
    String PROCESS_BUTTON = "SME451_S001_B003";
    String ROLE = "SME451_S001_C001";
    String USER_HELP_LINK = "SME451_S001_I018";
    String CREATE_CLIENT_TO_SALESFORCE_LINK = "SME451_S001_I019";
    String SUPERVISION_LINK = "SME451_S001_I025";
    String DOCUMENT_SCAN_LINK = "SME451_S001_I028";
    String CASH_POOLING_LINK = "SME451_S001_I031";
    String TEMPLATES_LINK = "SME451_S001_I038";
    String EVENT_CALENDAR_LINK = "SME451_S001_I034";
    String SIGNPOST_LINK = "SME451_S001_I032";
    String PROPOSAL_XPATH = "//*[@id='SME451_S001_G001_UfoTable']/tbody//td[text()='%s']";

    @Click(BILL_GUARANTOR_LINK)
    EVD420_S001_RecordsOfBillGuarantors clickBillGuarantorLink();

    @Click(SEARCH_LINK)
    SME401_S001_SearchPage clickSearchLink();

    @Click(DOCUMENTS_SEARCH_PAGE)
    DMS402_S001_DocumentsSearchPage clickDocumentsLink();

    @Click(COLLATERAL_LINK)
    ZST425_S001_SearchCollateral clickCollateralLink();

    @Click(TASKS_LINK)
    DSB451_S001_SummaryOfTasks clickTasksLink();

    @Click(PRICING_APPROVAL_LINK)
    PRC402_S001_PricingApproval clickPricingApprovalLink();

    @Click(PROCESS_BUTTON)
    KOM401_S001_ProposalParameters clickProcessButton();

    @Click(USER_HELP_LINK)
    NAP401_S001_UserHelp clickUserHelpLink();

    @Click(SUPERVISION_LINK)
    SPV405_S002_SupervisionPage clickSupervisionLink();

    @Click(DOCUMENT_SCAN_LINK)
    DMS421_S001_DocumentScanPage clickDocumentScanLink();

    @Click(CASH_POOLING_LINK)
    CPL401_S001_CashPoolingPage clickCashPoolingLink();

    @Click(TEMPLATES_LINK)
    SME410_S001_TemplatesPage clickTemplatesLink();

    @Click(EVENT_CALENDAR_LINK)
    KAC402_S001_EventCalendarPage clickEventCalendarLink();

    @Click(SIGNPOST_LINK)
    SME451_S001_UfoCbLandingPage clickSignPostLink();

    @Click(CREATE_CLIENT_TO_SALESFORCE_LINK)
    SFC401_S001_CreateClientToSalesForce clickCreateToSalesForceLink();

    @Click(value = PROPOSAL_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    SME451_S001_UfoCbLandingPage selectProposal(String proposalId);

    @CustomAction
    default SME451_S001_UfoCbLandingPage switchToSignPostReportsWindowAndCheckUrl(String expectedUrl) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.switchToWindowByTitle("Sales Report | MONETA Money Bank");
        String urlFromPage = endpoint.getCurrentUrl();
        log("Url from report page is " + urlFromPage);
        Assertions.assertEquals(expectedUrl, urlFromPage, "You expected URL is " + expectedUrl + " active page URL is " + urlFromPage);
        return null;
    }

    @Click(value = PROPOSAL_XPATH + "[1]", by = Lookup.XPATH, isStringDynamicXpath = true)
    SME451_S001_UfoCbLandingPage clickFirstProposalByState(String state);

}
