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

import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ufo.operations.ufoOperations.PLK708_S001_DataChangesPage.PAGE_TITLE;
import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

@Wait(value = PAGE_TITLE, until = Until.VISIBLE)
public interface PLK708_S001_DataChangesPage extends WebFlow<PLK708_S001_DataChangesPage>, StoreAccessor {

    String PAGE_TITLE = "PLK708el11";
    String ADDRESS_FOR_SENDING_SELECT = "PLK708_S001_C001";
    String OM_ADDRESS_FOR_SENDING_SELECT = "PLK708_S001_C003";
    String STREET_INPUT = "PLK708_S001_U002";
    String VILLAGE_INPUT = "PLK708_S001_U008";
    String POST_OFFICE_INPUT = "PLK708_S001_U003";
    String POSTAL_CODE_INPUT = "PLK708_S001_U010";
    String DESCRIPTIVE_NUMBER_INPUT = "PLK708_S001_U017";
    String SAVE_BUTTON = "PLK708_S001_B003";
    String BACK_DART_BUTTON = "PLK708_S001_B001";

    @Select(value = ADDRESS_FOR_SENDING_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    PLK708_S001_DataChangesPage selectAddressForSending(String address);

    @Select(value = OM_ADDRESS_FOR_SENDING_SELECT, andWait = @Wait(explicitWaitSeconds = 1))
    PLK708_S001_DataChangesPage selectOMAddressForSending(String omAddress);

    @CustomAction
    default PLK708_S001_DataChangesPage checkStreetInput(String expectedStreet) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(expectedStreet, endpoint.getAttribute(STREET_INPUT, "value"), "The street doesn't match");
        return null;
    }

    @CustomAction
    default PLK708_S001_DataChangesPage checkVillageInput(String expectedVillage) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(expectedVillage, endpoint.getAttribute(VILLAGE_INPUT, "value"), "The village doesn't match");
        return null;
    }

    @CustomAction
    default PLK708_S001_DataChangesPage checkPostOfficeInput(String expectedPostOffice) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(expectedPostOffice, endpoint.getAttribute(POST_OFFICE_INPUT, "value"), "The post office doesn't match");
        return null;
    }

    @CustomAction
    default PLK708_S001_DataChangesPage checkPostalCodeInput(String expectedPostalCode) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(expectedPostalCode, endpoint.getAttribute(POSTAL_CODE_INPUT, "value"), "The postal code doesn't match");
        return null;
    }

    @CustomAction
    default PLK708_S001_DataChangesPage checkDescriptiveNumberInput(String expectedDescriptiveNumber) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(expectedDescriptiveNumber, endpoint.getAttribute(DESCRIPTIVE_NUMBER_INPUT, "value"), "The house number  doesn't match");
        return null;
    }

    @Click(value = SAVE_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STS701_S002_ClientDetailPage clickSaveButton();

    @Wait(value = SAVE_BUTTON, until = Until.VISIBLE)
    @Click(BACK_DART_BUTTON)
    STS701_S002_ClientDetailPage clickBackButton();
}