package cz.moneta.test.dsl.hypos.pages.hypokalkulacka;

import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.hypos.HyposEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.hypos.pages.hypokalkulacka.HypokalkulackaClientDetailPage.SAVE_CLIENT_BUTTON;

@Wait(value = SAVE_CLIENT_BUTTON, until = Until.VISIBLE)
public interface HypokalkulackaClientDetailPage extends HyposPageFlow<HypokalkulackaClientDetailPage>, StoreAccessor {
    String CLIENT_INPUT_DIV = "//div[@id='client-input']";
    String PIN_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-pin']";
    String FIRST_NAME_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-first-name']";
    String LAST_NAME_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-last-name']";
    String PHONE_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-cell']";
    String EMAIL_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-email']";
    String MARITAL_STATUS_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-marital-status']";
    String STAY_TYPE_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-stay-type']";
    String LIVING_TYPE_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-living-type']";
    String EDUCATION_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-education']";
    String BIRTH_DATE_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-dob']";
    String NATIONALITY_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-nationality']";
    String CLIENT_RELATION_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-relation']";
    String HOUSEHOLD_SELECT = CLIENT_INPUT_DIV + "//select[@id='client-household-nr']";
    String EMPLOYEE_INPUT = CLIENT_INPUT_DIV + "//input[@id='client-is-ge-employee']";

    String PIN_SEARCH_BUTTON = CLIENT_INPUT_DIV + "//input[@id='client-search-by-pin']";
    String SAVE_CLIENT_BUTTON = CLIENT_INPUT_DIV + "//input[@value='Uložit']";

    @TypeInto(PIN_INPUT)
    @Click(value = PIN_SEARCH_BUTTON, andWait = @Wait(value = PIN_SEARCH_BUTTON, until = Until.VISIBLE))
    HypokalkulackaClientDetailPage fillPinAndSearchPin(String pin);

    @TypeInto(FIRST_NAME_INPUT)
    HypokalkulackaClientDetailPage fillFirstName(String firstName);

    @TypeInto(LAST_NAME_INPUT)
    HypokalkulackaClientDetailPage fillLastName(String lastName);

    @TypeInto(PHONE_INPUT)
    HypokalkulackaClientDetailPage fillPhone(String phone);

    @TypeInto(EMAIL_INPUT)
    HypokalkulackaClientDetailPage fillEmail(String email);

    @Select(MARITAL_STATUS_SELECT)
    HypokalkulackaClientDetailPage selectMaritalStatus(String maritalStatus);

    @Select(STAY_TYPE_SELECT)
    HypokalkulackaClientDetailPage selectStayType(String stayType);

    @Select(LIVING_TYPE_SELECT)
    HypokalkulackaClientDetailPage selectLivingType(String livingType);

    @Select(EDUCATION_SELECT)
    HypokalkulackaClientDetailPage selectEducationType(String educationType);

    @TypeInto(value = BIRTH_DATE_INPUT, clear = true)
    HypokalkulackaClientDetailPage fillBirthDate(String birthDate);

    @Select(NATIONALITY_SELECT)
    HypokalkulackaClientDetailPage selectNationality(String nationality);

    @Select(CLIENT_RELATION_SELECT)
    HypokalkulackaClientDetailPage selectClientRelation(String clientRelation);

    @Select(HOUSEHOLD_SELECT)
    HypokalkulackaClientDetailPage selectHousehold(String household);

    @Click(SAVE_CLIENT_BUTTON)
    HypokalkulackaPage clickSaveClientButton();

    @CustomAction
    default HypokalkulackaClientDetailPage selectEmployee(boolean employee) {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        if (employee) {
            endpoint.click(() -> EMPLOYEE_INPUT);
        }
        return null;
    }
}