package cz.moneta.test.dsl.ufo.banka.pages.fon;

import cz.moneta.test.dsl.ufo.banka.pages.income.PIM001_S001_IncomeEditPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

@Wait(value = CIF113_S001_ChangeDataFO.CIF_CHANGE_DATA_FO_PAGE_LABEL, by = Lookup.XPATH, waitSecondsForElement = 60)
public interface CIF113_S001_ChangeDataFO extends WebFlow<CIF113_S001_ChangeDataFO>, StoreAccessor {

    String BIRTH_NUMBER_KEY = "BIRTH_NUMBER";
    String LAST_NAME_KEY = "LAST_NAME";
    String FIRST_NAME_KEY = "FIRST_NAME";
    String MARITAL_STATUS_KEY = "MARITAL_STATUS";
    String HOUSING_TYPE_KEY = "HOUSING_TYPE";
    String EDUCATION_KEY = "EDUCATION";
    String NATIONALITY_KEY = "NATIONALITY";
    String FIRST_ID_CARD_TYPE_KEY = "FIRST_ID_CARD_TYPE";
    String FIRST_ID_CARD_NUMBER_KEY = "FIRST_ID_CARD_NUMBER";
    String FIRST_ID_CARD_EXPIRATION_DATE_KEY = "FIRST_ID_CARD_EXPIRATION_DATE";
    String SECOND_ID_CARD_TYPE_KEY = "SECOND_ID_CARD_TYPE";
    String SECOND_ID_CARD_NUMBER_KEY = "SECOND_ID_CARD_NUMBER";
    String SECOND_ID_CARD_EXPIRATION_DATE_KEY = "SECOND_ID_CARD_EXPIRATION_DATE";
    String ADDRESS_KEY = "ADDRESS";
    String MOBILE_PHONE_KEY = "MOBILE_PHONE";
    String LANDLINE_KEY = "LANDLINE";
    String EMAIL_KEY = "EMAIL";
    String DEPENDANTS_NUMBER_KEY = "DEPENDANTS_NUMBER";
    String CIF_CHANGE_DATA_FO_PAGE_LABEL = "//div[text()='CIF113_S001']";
    String FIRST_NAME_INPUT = "CIF113_S001_U003";
    String LAST_NAME_INPUT = "CIF113_S001_U005";
    String EDUCATION_SELECT = "CIF113_S001_C008";
    String BIRTH_NUMBER_INPUT = "CIF113_S001_U001";
    String NATIONALITY_SELECT = "CIF113_S001_C019";
    String ADDRESS_STREET_INPUT = "CIF113_S001_E012";
    String ADDRESS_DESCRIPTIVE_NUMBER_INPUT = "CIF113_S001_E025";
    String ADDRESS_ORIENTATION_NUMBER_INPUT = "CIF113_S001_E026";
    String ADDRESS_CITY_INPUT = "CIF113_S001_E027";
    String ADDRESS_ZIP_CODE_INPUT = "CIF113_S001_E029";
    String ADDRESS_POST_INPUT = "CIF113_S001_E030";
    String ADDRESS_COUNTRY_SELECT = "CIF113_S001_C004";
    String EMAIL_INPUT = "CIF113_S001_U017";
    String MOBILE_PHONE_CODE_INPUT = "CIF113_S001_U020";
    String MOBILE_NUM_INPUT = "CIF113_S001_U021";
    String LANDLINE_CODE_INPUT = "CIF113_S001_E060";
    String LANDLINE_INPUT = "CIF113_S001_E061";
    String FIRST_ID_CARD_TYPE_SELECT = "CIF113_S001_C020";
    String FIRST_ID_CARD_NUMBER_INPUT = "CIF113_S001_E007";
    String FIRST_ID_CARD_VALID_TO_INPUT = "CIF113_S001_E011";
    String SECOND_ID_CARD_TYPE_SELECT = "CIF113_S001_C022";
    String SECOND_ID_CARD_NUMBER_INPUT = "CIF113_S001_E048";
    String MARITAL_STATUS_SELECT = "CIF113_S001_C006";
    String HOUSING_TYPE_SELECT = "CIF113_S001_C007";
    String SECOND_ID_CARD_VALID_TO_INPUT = "CIF113_S001_E049";
    String SEND_BUTTON = "CIF113_S001_B002";
    String BACK_BUTTON = "CIF113_S001_B003";
    String EDIT_INCOME_BUTTON = "CIF113_S001_B032";
    String DEPENDANTS_NUMBER_INPUT = "CIF113_S001_U037";

    @Click(SEND_BUTTON)
    CIF113_S001_ChangeDataFOTransitions clickSend();

    @Click(BACK_BUTTON)
    CIF113_S001_ChangeDataFOTransitions clickBack();

    @TypeInto(value = LAST_NAME_INPUT, clear = true)
    CIF113_S001_ChangeDataFO changeLastName(String newLastName);

    @TypeInto(value = EMAIL_INPUT, clear = true)
    CIF113_S001_ChangeDataFO changeEmail(String newEmail);

    @TypeInto(value = MOBILE_NUM_INPUT, clear = true)
    CIF113_S001_ChangeDataFO changeMobileNum(String newMobileNum);

    @TypeInto(value = FIRST_ID_CARD_VALID_TO_INPUT, clear = true)
    @TypeInto(value = SECOND_ID_CARD_VALID_TO_INPUT, clear = true)
    CIF113_S001_ChangeDataFO updateIDValidation(String endOfValidation, String endOfValidation2);

    @Click(EDIT_INCOME_BUTTON)
    PIM001_S001_IncomeEditPage clickEditIncome();

    @CustomAction
    default CIF113_S001_ChangeDataFO storeBirthNumber() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(BIRTH_NUMBER_KEY, endpoint.getAttribute(BIRTH_NUMBER_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeEducation() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(EDUCATION_KEY, endpoint.getSelectedFirstItemText(EDUCATION_SELECT));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeLastName() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(LAST_NAME_KEY, endpoint.getAttribute(LAST_NAME_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeFirstName() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(FIRST_NAME_KEY, endpoint.getAttribute(FIRST_NAME_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeNationality() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(NATIONALITY_KEY, endpoint.getSelectedFirstItemText(NATIONALITY_SELECT));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeAddress() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        String addressOrientationNumber = endpoint.getAttribute(ADDRESS_ORIENTATION_NUMBER_INPUT, "value");
        String orientationNumber = (!addressOrientationNumber.isEmpty()) ? "/" + addressOrientationNumber + "\n" : "\n";
        String address = endpoint.getAttribute(ADDRESS_STREET_INPUT, "value") + " " +
                endpoint.getAttribute(ADDRESS_DESCRIPTIVE_NUMBER_INPUT, "value") +
                orientationNumber +
                endpoint.getAttribute(ADDRESS_CITY_INPUT, "value") + "\n" +
                endpoint.getAttribute(ADDRESS_ZIP_CODE_INPUT, "value") + " " +
                endpoint.getAttribute(ADDRESS_POST_INPUT, "value") + "\n" +
                endpoint.getSelectedFirstItemText(ADDRESS_COUNTRY_SELECT);
        this.store(ADDRESS_KEY, address);
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeEmail() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(EMAIL_KEY, endpoint.getAttribute(EMAIL_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeMobilePhoneIncludedCode() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        String mobilePhone = endpoint.getAttribute(MOBILE_PHONE_CODE_INPUT, "value")
                + endpoint.getAttribute(MOBILE_NUM_INPUT, "value");
        this.store(MOBILE_PHONE_KEY, mobilePhone);
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeLandlineIncludedCode() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        String landline = endpoint.getAttribute(LANDLINE_CODE_INPUT, "value")
                + endpoint.getAttribute(LANDLINE_INPUT, "value");
        this.store(LANDLINE_KEY, landline);
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeFirstIdCardType() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        String firstIdCardType = endpoint.getSelectedFirstItemText(FIRST_ID_CARD_TYPE_SELECT);
        this.store(FIRST_ID_CARD_TYPE_KEY, firstIdCardType);
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeFirstIdCardNumber() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(FIRST_ID_CARD_NUMBER_KEY, endpoint.getAttribute(FIRST_ID_CARD_NUMBER_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeFirstIdCardExpirationDate() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(FIRST_ID_CARD_EXPIRATION_DATE_KEY, endpoint.getAttribute(FIRST_ID_CARD_VALID_TO_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeSecondIdCardType() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        String secondIdCardType = endpoint.getSelectedFirstItemText(SECOND_ID_CARD_TYPE_SELECT);
        this.store(SECOND_ID_CARD_TYPE_KEY, secondIdCardType);
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeSecondIdCardNumber() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(SECOND_ID_CARD_NUMBER_KEY, endpoint.getAttribute(SECOND_ID_CARD_NUMBER_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeSecondIdCardExpirationDate() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(SECOND_ID_CARD_EXPIRATION_DATE_KEY, endpoint.getAttribute(SECOND_ID_CARD_VALID_TO_INPUT, "value"));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeMaritalStatus() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(MARITAL_STATUS_KEY, endpoint.getSelectedFirstItemText(MARITAL_STATUS_SELECT));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeHousingType() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(HOUSING_TYPE_KEY, endpoint.getSelectedFirstItemText(HOUSING_TYPE_SELECT));
        return null;
    }

    @CustomAction
    default CIF113_S001_ChangeDataFO storeDependantsNumber() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        store(DEPENDANTS_NUMBER_KEY, endpoint.getAttribute(DEPENDANTS_NUMBER_INPUT, "value"));
        return null;
    }

}
