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

import cz.moneta.test.dsl.hypos.components.Menu;
import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.TypeInto;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.hypos.pages.contract.realty.RealtyPage.PAGE_TITLE;
import static cz.moneta.test.dsl.hypos.pages.contract.realty.RealtyPage.SEARCH_REALTY_LINK;

@Wait({PAGE_TITLE, SEARCH_REALTY_LINK})
public interface RealtyPage extends HyposPageFlow<RealtyPage>, Menu {
    String PAGE_TITLE = "//h1[contains(text(),'Detail obchodu')]";
    String SEARCH_REALTY_LINK = "//a[contains(text(),'vyhledání nemovitosti a přiřazení jako zajištění')]";
    String LAND_AREA_REGISTRY_DRAFT_DATE_INPUT = "//th[contains(text(),'Datum podání návrhu na vklad ZP')]//following::input[@name='datum[1]']";
    String LAND_AREA_REGISTRY_ENTRY_DATE_INPUT = "//th[contains(text(),'Datum zápisu ZP do KN')]//following::input[@name='datum[3]']";
    String LAND_AREA_REGISTRY_LIEN_1ST_INPUT = "//th[contains(text(),'Datum, kdy se banka dozvěděla, že je ZP na 1. místě')]//following::input[@name='datum[4]']";
    String SAVE_UNIT_DATES_INPUT = "//form[contains(@class,'sec-dateStore')]//input[@value='Uložit']";

    String REALTY_DETAIL = "a[contains(text(), 'Zobrazit detail celku')]";
    String REALTY_DETAIL_LINK = "(//" + REALTY_DETAIL + ")[1]";
    String REALTY_DETAIL_BY_REALTY_NUMBER_LINK = "//table[contains(@class,'content')]//td[text()='%s']//following::" + REALTY_DETAIL;

    @Click(SEARCH_REALTY_LINK)
    SearchRealtyPage clickSearchRealty();

    @Click(REALTY_DETAIL_LINK)
    UnitDetailPage clickRealtyDetail();

    @Click(value = REALTY_DETAIL_BY_REALTY_NUMBER_LINK, isStringDynamicXpath = true)
    UnitDetailPage clickRealtyDetail(String realtyNumber);

    @TypeInto(LAND_AREA_REGISTRY_DRAFT_DATE_INPUT)
    RealtyPage fillLandAreaRegistryDraftDate(String date);

    @TypeInto(LAND_AREA_REGISTRY_ENTRY_DATE_INPUT)
    RealtyPage fillLandAreaRegistryEntryDate(String date);

    @TypeInto(LAND_AREA_REGISTRY_LIEN_1ST_INPUT)
    RealtyPage fillLandAreaRegistryLien1stDate(String date);

    @Click(value = SAVE_UNIT_DATES_INPUT, andWait = @Wait(value = LOADER, until = Until.GONE))
    RealtyPage clickSaveLandRegistryDates();
}