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 org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ufo.operations.recorder.CRC710_S001_RecorderMainPage.LOAD_IMG_XPATH;
import static cz.moneta.test.dsl.ufo.operations.recorder.panels.CRC710_S001_SubjectRecorderPanel.NUMBER_OF_CONTRACT;
import static cz.moneta.test.dsl.ufo.operations.recorder.panels.CRC710_S001_WritingsToCrcPanel.WRITINGS_TO_CRC_INNER_PANEL;
import static cz.moneta.test.harness.support.web.Lookup.XPATH;

@Wait(WRITINGS_TO_CRC_INNER_PANEL)
public interface CRC710_S001_WritingsToCrcPanel extends WebFlow<CRC710_S001_RecorderMainPage>, StoreAccessor {

    String WRITINGS_TO_CRC_INNER_PANEL = "CRC710_S001_Y005_innerPanel";
    String FIRST_WRITING_ADDED_DATE_DIV = "CRC710_S001_L122-1";
    String ADDED_DATE_STORE = "ADDED_DATE";
    String FIRST_WRITING_DESCRIPTION = "CRC710_S001_L120-1";
    String FIRST_WRITING_CONTRACT_NUMBER = "CRC710_S001_L126-1";
    String FIRST_WRITING_DETAIL = "CRC710_S001_P015-1";

    @Wait(value = FIRST_WRITING_DESCRIPTION, until = Until.VISIBLE)
    @CheckElementPresent(FIRST_WRITING_DESCRIPTION)
    CRC710_S001_RecorderMainPage checkPresentOfRequirement();

    @CustomAction
    default CRC710_S001_RecorderMainPage checkNumberOfContractInRequirement() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(5, FIRST_WRITING_CONTRACT_NUMBER);
        Assertions.assertEquals(endpoint.getAttribute(NUMBER_OF_CONTRACT, "value"), endpoint.getText(FIRST_WRITING_CONTRACT_NUMBER));
        return null;
    }

    @StoreElementContent(value = FIRST_WRITING_ADDED_DATE_DIV, storeKey = ADDED_DATE_STORE)
    CRC710_S001_RecorderMainPage storeFirstLineAddedDate();

    @Wait(value = FIRST_WRITING_DETAIL, until = Until.VISIBLE)
    @Click(value = FIRST_WRITING_DETAIL, andWait = @Wait(value = LOAD_IMG_XPATH, by = XPATH, until = Until.GONE))
    CRC710_S001_RecorderMainPage clickDetailOfCrcRequirement();
}
