package cz.moneta.test.dsl.ufo.operations.shared.topmenu;

import cz.moneta.test.dsl.ufo.operations.recorder.CRC710_S001_RecorderMainPage;
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 XXX702_Requirements<T extends WebFlow<T>> extends WebFlow<T>, StoreAccessor {

    String FIRST_REQUIREMENT_DESCRIPTION = "XXX702_T001_L269-1";
    String FIRST_REQUIREMENT_SUBMIT_DATE = "XXX702_T001_L286-1";
    String FIRST_REQUIREMENT_SOLVE_DATE = "XXX702_T001_L312-1";
    String FIRST_REQUIREMENT_DETAIL_BUTTON = "XXX702_T001_P035-1";

    String SECOND_REQUIREMENT_DESCRIPTION = "XXX702_T001_L269-2";

    String REFRESH_REQ_BUTTON = "XXX702_T001_B001";

    @CheckElementPresent(FIRST_REQUIREMENT_DESCRIPTION)
    T checkFirstRequirementDescriptionPresence();


    @CheckElementContent(FIRST_REQUIREMENT_DESCRIPTION)
    T assertFirstRequirementDescription(String description);

    @CheckElementContent(FIRST_REQUIREMENT_SOLVE_DATE)
    T assertFirstRequirementSolveDate(String expectedDate);


    @GetElementContent(FIRST_REQUIREMENT_SUBMIT_DATE)
    String getFirstRequirementSubmitDate();

    @GetElementContent(FIRST_REQUIREMENT_SOLVE_DATE)
    String getFirstRequirementSolveDate();

    @CustomAction
    default CRC710_S001_RecorderMainPage clickFirstRequirementDetail() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(15, FIRST_REQUIREMENT_DETAIL_BUTTON);
        endpoint.click(() -> FIRST_REQUIREMENT_DETAIL_BUTTON);
        endpoint.focusToNewPopup(5);
        return null;
    }


    @CheckElementContent(SECOND_REQUIREMENT_DESCRIPTION)
    T assertSecondRequirementDescription(String description);


    @Wait(value = REFRESH_REQ_BUTTON, until = Until.VISIBLE)
    @Click(value = REFRESH_REQ_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    XXX702_Requirements<T> clickRefreshRequirements();

}