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 static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

public interface ZAS701_S002_SendingOffersAndManualsPage extends WebFlow<ZAS701_S002_SendingOffersAndManualsPage>, StoreAccessor {

    String BACK_DART_BUTTON = "ZAS701_S002_P007";
    String SEARCH_BUTTON = "ZAS701_S002_B002";
    String SECOND_ROW_SELECTED_DOCUMENTS_FOR_SENDING_ID = "ufo-et-ZAS701_S002_F001_row_2";
    String SELECTED_DOCUMENTS_FOR_SENDING_LABEL = "ZAS701_S002_L025";
    String SEND_BUTTON = "ZAS701_S002_B001";
    String CLIENT_SEGMENT_COMBOBOX = "ZAS701_S002_C001";
    String PRODUCT_GROUP_COMBOBOX = "ZAS701_S002_C003";
    String DOCUMENT_DETAIL_BUTTON = "ZAS701_S002_P001-1";
    String ADD_FIRST_DOCUMENT_BUTTON = "ZAS701_S002_P003-1";
    String ADD_SECOND_DOCUMENT_BUTTON = "ZAS701_S002_P003-2";
    String EMAIL_INPUT = "ZAS701_S002_E001";
    String CONTACT_FOR_CLIENT_COMBOBOX = "ZAS701_S002_C004";

    @Wait(value = SEARCH_BUTTON, until = Until.VISIBLE)
    @CheckElementPresent(SEARCH_BUTTON)
    ZAS701_S002_SendingOffersAndManualsPage assertOffers();

    @Click(BACK_DART_BUTTON)
    STS701_S002_ClientDetailPage clickBackButton();

    @Wait(value = SECOND_ROW_SELECTED_DOCUMENTS_FOR_SENDING_ID, until = Until.VISIBLE)
    @CheckElementPresent(SECOND_ROW_SELECTED_DOCUMENTS_FOR_SENDING_ID)
    ZAS701_S002_SendingOffersAndManualsPage checkRecordsOfDocumentsForSending();

    @Wait(value = SELECTED_DOCUMENTS_FOR_SENDING_LABEL, until = Until.VISIBLE)
    @CheckElementContent(SELECTED_DOCUMENTS_FOR_SENDING_LABEL)
    ZAS701_S002_SendingOffersAndManualsPage checkSelectedDocumentsForSending(String label);

    @Wait(value = SEND_BUTTON, until = Until.VISIBLE)
    @CheckElementPresent(SEND_BUTTON)
    ZAS701_S002_SendingOffersAndManualsPage checkSendButton();

    @Select(value = CLIENT_SEGMENT_COMBOBOX, selectByOrder = true)
    ZAS701_S002_SendingOffersAndManualsPage selectSegmentOfClient(int orderValue);

    @Select(PRODUCT_GROUP_COMBOBOX)
    ZAS701_S002_SendingOffersAndManualsPage selectProductGroup(String productGroup);

    @Click(value = SEARCH_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ZAS701_S002_SendingOffersAndManualsPage clickSearch();

    @CustomAction
    default ZAS701_S002_SendingOffersAndManualsPage clickDocumentDetailAndCheck() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(20, Until.CLICKABLE, DOCUMENT_DETAIL_BUTTON);
        endpoint.click(() -> DOCUMENT_DETAIL_BUTTON);
        endpoint.switchToOtherWindow(10, 2);
        return null;
    }

    @CustomAction
    default ZAS701_S002_SendingOffersAndManualsPage closeDocumentWindowAndSwitchToCurrentWindow() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.closeCurrentWindow();
        endpoint.switchToOtherWindow(10, 1);
        return null;
    }

    @Click(value = ADD_FIRST_DOCUMENT_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, until = Until.GONE, by = Lookup.CLASSNAME))
    ZAS701_S002_SendingOffersAndManualsPage clickAddFirstDocument();

    @Click(value = ADD_SECOND_DOCUMENT_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, until = Until.GONE, by = Lookup.CLASSNAME))
    ZAS701_S002_SendingOffersAndManualsPage clickAddSecondDocument();

    @TypeInto(value = EMAIL_INPUT, clear = true)
    ZAS701_S002_SendingOffersAndManualsPage typeIntoEmailInput(String email);

    @Select(CONTACT_FOR_CLIENT_COMBOBOX)
    ZAS701_S002_SendingOffersAndManualsPage selectContactForClient(String name);

    @Click(value = SEND_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STS701_S002_ClientDetailPage clickSend();
}