package cz.moneta.test.dsl.ufo.operations.recorder.panels;

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.recorder.panels.CRC710_S001_SubjectRecorderPanel.INSERT_SUBJECT_FROM_CLIPBOARD;
import static cz.moneta.test.dsl.ufo.operations.recorder.panels.CRC710_S001_SubjectRecorderPanel.SUBJECT_INNER_PANEL_DIV;
import static cz.moneta.test.harness.support.web.Lookup.XPATH;
import static cz.moneta.test.harness.support.web.Until.CLICKABLE;
import static cz.moneta.test.harness.support.web.Until.GONE;

@Wait(SUBJECT_INNER_PANEL_DIV)
public interface CRC710_S001_SubjectRecorderPanel extends WebFlow<CRC710_S001_RecorderMainPage>, StoreAccessor {

    String SUBJECT_INNER_PANEL_DIV = "CRC710_S001_Y007_innerPanel";
    String INSERT_SUBJECT_FROM_CLIPBOARD = "CRC710_S001_B002";
    String SUBJECT_BIRTH_NUMBER_RADIO = "CRC710_S001_R001_1";
    String SUBJECT_CIF_RADIO = "CRC710_S001_R001_12";
    String SUBJECT_INPUT = "CRC710_S001_E001";
    String SUBJECT_LOAD_BUTTON = "CRC710_S001_P012";
    String NUMBER_OF_CONTRACT = "CRC710_S001_E002";
    String NAME_OF_CLIENT = "CRC710_S001_L061";
    String SUBJECT_NAME_FILLED_DIV_XPATH = "//div[@id='" + NAME_OF_CLIENT + "' and text()]";
    String SUBJECT_WRITE_TO_CRS_BUTTON_ID = "CRC710_S001_B003";

    @Wait(value = INSERT_SUBJECT_FROM_CLIPBOARD, until = CLICKABLE)
    @Click(INSERT_SUBJECT_FROM_CLIPBOARD)
    CRC710_S001_RecorderMainPage clickInsertSubjectFromClipboard();

    @Wait(value = SUBJECT_BIRTH_NUMBER_RADIO, until = Until.CLICKABLE)
    @Click(value = SUBJECT_BIRTH_NUMBER_RADIO, andWait = @Wait(explicitWaitSeconds = 1))
    CRC710_S001_RecorderMainPage clickBirthNumberInSubject();

    @Wait(value = SUBJECT_CIF_RADIO, until = Until.CLICKABLE)
    @Click(value = SUBJECT_CIF_RADIO, andWait = @Wait(explicitWaitSeconds = 1))
    CRC710_S001_RecorderMainPage clickCifInSubject();

    @TypeInto(value = SUBJECT_INPUT, clear = true)
    CRC710_S001_RecorderMainPage fillSearchSubjectInput(String value);

    @Wait(SUBJECT_LOAD_BUTTON)
    @Click(value = SUBJECT_LOAD_BUTTON, andWait = @Wait(value = SUBJECT_NAME_FILLED_DIV_XPATH, by = XPATH, waitSecondsForElement = 30))
    CRC710_S001_RecorderMainPage clickLoadSubjectArrow();

    @Wait(value = NAME_OF_CLIENT, until = Until.VISIBLE)
    @CheckElementContent(NAME_OF_CLIENT)
    CRC710_S001_RecorderMainPage checkNameOfClient(String name);

    @Wait(value = SUBJECT_NAME_FILLED_DIV_XPATH, by = XPATH, until = GONE, waitSecondsForElement = 30)
    CRC710_S001_RecorderMainPage waitForSubjectNameVanish();

    @Click(SUBJECT_WRITE_TO_CRS_BUTTON_ID)
    CRC710_S001_RecorderMainPage submitRequest();

    @CustomAction
    default CRC710_S001_RecorderMainPage insertNumberOfContract() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.typeWithControlDown(NUMBER_OF_CONTRACT, "v");
        return null;
    }
}