package cz.moneta.test.dsl.ufo.operations.ufoOperations;

import cz.moneta.test.dsl.ufo.operations.shared.PrintAppPage;
import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.operations.ufoOperations.OTP701_S001_UniversalPrintProcessPage.PAGE_DIV;

@Wait(PAGE_DIV)
public interface OTP701_S001_UniversalPrintProcessPage extends StoreAccessor, WebFlow<OTP701_S001_UniversalPrintProcessPage> {
    String PAGE_DIV = "OTP701_S001_X001";
    String DEPARTMENT_COMBOBOX = "OTP701_S001_C001";
    String CATEGORY_COMBOBOX = "OTP701_S001_C004";
    String TEMPLATE_COMBOBOX = "OTP701_S001_C002";
    String PRINT_BUTTON = "OTP701_S001_B001";
    String GENDER_RADIO = "OTP701_S001_R001_3";
    String ANOTHER_ADDRESS_RADIO = "OTP701_S001_H001_1";
    String NAME_INPUT = "OTP701_S001_E015";
    String STREET_INPUT = "OTP701_S001_E016";
    String BUILDING_NUMBER_INPUT = "OTP701_S001_E017";
    String STREET_NUMBER_INPUT = "OTP701_S001_E018";
    String CITY_INPUT = "OTP701_S001_E019";
    String POSTAL_CODE_INPUT = "OTP701_S001_E020";
    String ADDRESS_BUTTON = "IPP702_S001_G001-0";


    @Select(value = DEPARTMENT_COMBOBOX, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OTP701_S001_UniversalPrintProcessPage selectDepartment(String department);

    @Select(value = CATEGORY_COMBOBOX, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OTP701_S001_UniversalPrintProcessPage selectCategory(String category);

    @Select(value = TEMPLATE_COMBOBOX, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OTP701_S001_UniversalPrintProcessPage selectTemplate(String template);

    @Click(value = PRINT_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    PSP701_S004_PrintTemplatePage clickPrint();

    @CustomAction
    default PrintAppPage clickPrintInteractive() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> PRINT_BUTTON);
        endpoint.focusToNewPopup(10);
        return null;
    }

    @Click(value = PRINT_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OTP701_S001_UniversalPrintProcessPage clickPrintWithAnotherAddress();

    @CustomAction
    default OTP701_S001_UniversalPrintProcessPage selectGenderIfVisible() {
        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(5, GENDER_RADIO, Lookup.ID)) {
            endpoint.click(() -> GENDER_RADIO);
        }
        return null;
    }

    @Click(value = ANOTHER_ADDRESS_RADIO, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OTP701_S001_UniversalPrintProcessPage clickAnotherAddress();

    @TypeInto(NAME_INPUT)
    OTP701_S001_UniversalPrintProcessPage fillNameInput(String name);

    @TypeInto(STREET_INPUT)
    OTP701_S001_UniversalPrintProcessPage fillStreetInput(String street);

    @TypeInto(BUILDING_NUMBER_INPUT)
    OTP701_S001_UniversalPrintProcessPage fillBuildingNumberInput(String buildingNumber);

    @TypeInto(STREET_NUMBER_INPUT)
    OTP701_S001_UniversalPrintProcessPage fillStreetNumberInput(String streetNumber);

    @TypeInto(CITY_INPUT)
    OTP701_S001_UniversalPrintProcessPage fillCityInput(String city);

    @TypeInto(POSTAL_CODE_INPUT)
    OTP701_S001_UniversalPrintProcessPage fillPostalCodeInput(String postalCode);

    @Click(value = ADDRESS_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    OTP701_S001_UniversalPrintProcessPage clickAddress();
}
