package cz.moneta.test.dsl.brokerportal.contract;

import cz.moneta.test.dsl.brokerportal.contractdetail.ContractDetailPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.brokerportal.contract.ContractListPage.CONTRACT_ROW;

@Wait(value = CONTRACT_ROW, waitSecondsForElement = 60)
public interface ContractListPage extends WebFlow<ContractListPage>, StoreAccessor {
    String SEARCH_INPUT = "//input[@id='otherText']";
    String SEARCH_SELECT_BY_TYPE = "//div[@id='otherSelect']//input";
    String SEARCH_ACTUAL_STATES = "//div[@id='actualStates']//input";
    String SEARCH_BUTTON = "//button[text()='Zobrazit']";
    String CONTRACT_STATE = "//p[@title='%s']";
    String CONTRACT_ROW = "//div[@class='c-card c-card--small u-mb--large withPointers']/div[@class='c-card__header']//*[@class='h-row']";
    String LOADER = "//div[contains(@class, 'c-loader')]";

    @TypeInto(value = SEARCH_SELECT_BY_TYPE, clear = true)
    @KeyPress(Key.ENTER)
    ContractListPage selectBy(String type);

    @TypeInto(SEARCH_ACTUAL_STATES)
    @KeyPress(Key.ENTER)
    ContractListPage selectState(String state);

    @TypeInto(SEARCH_INPUT)
    ContractListPage insertContractId(String contractId);

    @Click(value = SEARCH_BUTTON, andWait = @Wait(value = LOADER, until = Until.GONE, waitSecondsForElement = 60))
    ContractListPage searchContracts();

    @Click(CONTRACT_ROW)
    ContractDetailPage openContract();

    @CheckElementPresent(value = CONTRACT_STATE, isStringDynamicXpath = true)
    ContractListPage checkContractState(String state);
}