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

import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.dsl.hypos.pages.cadaster.CadasterRedocDetailPage;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.Select;
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.SearchRealtyPage.PAGE_TITLE;
import static cz.moneta.test.dsl.hypos.pages.contract.realty.SearchRealtyPage.REALTY_SEARCH_BUTTON;
import static cz.moneta.test.dsl.hypos.pages.contract.realty.SearchRealtyPage.SEARCH_DATA_TABLE;

@Wait({PAGE_TITLE, SEARCH_DATA_TABLE, REALTY_SEARCH_BUTTON})
public interface SearchRealtyPage extends HyposPageFlow<SearchRealtyPage> {
    String PAGE_TITLE = "//h2[text()='Vyhledání nemovitosti']";
    String SEARCH_DATA_TABLE = "//table[@id='search-data']";
    String LAND_AREA_NAME_INPUT = SEARCH_DATA_TABLE + "//input[@id='nazev-katuz']";
    String LAND_AREA_CODE_INPUT = SEARCH_DATA_TABLE + "//input[@id='kod-katuz']";
    String LV_INPUT = SEARCH_DATA_TABLE + "//input[@id='cislo-lv']";
    String LAND_AREA_AUTOSUGGEST_LINK = "//a[contains(text(),'%s')]";
    String DESCRIPTIVE_NUMBER = SEARCH_DATA_TABLE + "//input[@name='house_no']";
    String REGISTRATION_NUMBER = "//input[@name='reg_no']";
    String FLAT_NUMBER = SEARCH_DATA_TABLE + "//input[@name='flat_no']";
    String REALTY_TYPE_SELECT = "//select[@title='Typ hledané nemovitosti']";
    String REALTY_SEARCH_BUTTON = "//input[@value='Vyhledat']";
    String CREATE_NEW_UNIT_LINK = "//a[contains(text(),'vytvořit nový celek')]";
    String CREATE_NEW_UNIT_SEARCH_LINK = "//table//a[contains(text(),'nový celek')]";
    String REDOC_DETAIL_LINK = "//a[contains(text(),'LV %s')]";

    @Select(value = REALTY_TYPE_SELECT, andWait = @Wait(value = LAND_AREA_NAME_INPUT, until = Until.VISIBLE))
    SearchRealtyPage selectRealtyType(String realtyType);

    @TypeInto(value = LAND_AREA_NAME_INPUT, clear = true, andWait = @Wait(value = LAND_AREA_AUTOSUGGEST_LINK, until = Until.VISIBLE, isStringDynamicXpath = true))
    SearchRealtyPage fillAreaName(String area);

    @TypeInto(value = LAND_AREA_CODE_INPUT, clear = true)
    SearchRealtyPage fillAreaCode(String area);

    @TypeInto(value = LV_INPUT, clear = true)
    SearchRealtyPage fillLv(String lv);

    @Click(value = LAND_AREA_AUTOSUGGEST_LINK, isStringDynamicXpath = true)
    SearchRealtyPage clickAutosuggestLink(String landArea);

    @Click(value = REDOC_DETAIL_LINK, isStringDynamicXpath = true)
    CadasterRedocDetailPage clickRedocDetail(String lv);

    @TypeInto(DESCRIPTIVE_NUMBER)
    SearchRealtyPage fillDescriptiveNumber(String number);

    @TypeInto(REGISTRATION_NUMBER)
    SearchRealtyPage fillRegistrationNumber(String number);

    @TypeInto(FLAT_NUMBER)
    SearchRealtyPage fillFlatNumber(String number);

    @Click(REALTY_SEARCH_BUTTON)
    SearchRealtyPage clickSearchButton();

    @Wait(CREATE_NEW_UNIT_LINK)
    @Click(CREATE_NEW_UNIT_LINK)
    CreateNewUnitPage clickCreateNewUnit();

    @Click(CREATE_NEW_UNIT_SEARCH_LINK)
    CreateNewUnitPage clickCreateNewSearchUnit();
}