package cz.moneta.test.dsl.ib.cards.application;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.dsl.ib.cards.CardsVerticalMenu;
import cz.moneta.test.dsl.ib.cards.application.contract.PrepareContractPage;
import cz.moneta.test.dsl.ib.components.MainMenu;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ib.cards.application.ApplicationsOverviewPage.PAGE_NAME;

@Wait(PAGE_NAME)
public interface ApplicationsOverviewPage extends IbPageFlow<ApplicationsOverviewPage>,
        CardsVerticalMenu, MainMenu, StoreAccessor {
    String PAGE_NAME = "//*[@id=\"x31809652\"]/table/tbody/tr[1]/td/table/tbody/tr/td/b[text()='Žádost o kreditní kartu']";

    String FIRST_APPLICATION_ID = "//*[@id=\"x31809652\"]/table/tbody/tr[3]/td[1]";
    String FIRST_APPLICATION_STATUS = "//*[@id=\"x31809652\"]/table/tbody/tr[3]/td[2]";
    String FIRST_APPLICATION_PROMO = "//*[@id=\"x31809652\"]/table/tbody/tr[3]/td[4]";
    String FIRST_APPLICATION_LIMIT = "//*[@id=\"x31809652\"]/table/tbody/tr[3]/td[5]";

    String FIRST_APPLICATION_APPROVED = FIRST_APPLICATION_STATUS + "[text()='Schválená']";

    String SIGN_APPLICATION_BUTTON = "//*[@id=\"x31809652\"]/table/tbody/tr[5]/td/a[1]";

    @CustomAction
    default ApplicationsOverviewPage waitForApproval() {
        IbEndpoint endpoint = getEndpoint(IbEndpoint.class);
        endpoint.waitForElementAndRefresh(FIRST_APPLICATION_APPROVED, CardsVerticalMenu.APPLICATIONS_OVERVIEW_ANCHOR, Lookup.XPATH, Lookup.DEFAULT, 300, 20);
        return null;
    }

    @CheckElementContent(FIRST_APPLICATION_STATUS)
    ApplicationsOverviewPage checkFirstApplicationStatus(String status);

    @CheckElementContent(FIRST_APPLICATION_LIMIT)
    ApplicationsOverviewPage checkFirstApplicationLimit(String limit);

    @Click(SIGN_APPLICATION_BUTTON)
    PrepareContractPage signApplicationAndContinueToPrepareContractPage();
}
