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

import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.contactForwarding.XCM701_S001_ContactForwardingPage;
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.contactForwarding.panels.XCM701_S001_EcommPanel.SEND_BUTTON;

@Wait(value = SEND_BUTTON, until = Until.VISIBLE)
public interface XCM701_S001_EcommPanel extends XCM701_S001_ContactForwardingPage {

    String NAME_INPUT = "XCM701_S001_E037";
    String SURNAME_INPUT = "XCM701_S001_E039";
    String REASON_OF_HANDOVER = "XCM701_S001_C001";
    String CALENDAR_INPUT = "XCM701_S001_E032";
    String AVAILABILITY_TIME_INPUT = "XCM701_S001_E041";
    String TELEPHONE_INPUT = "XCM701_S001_E033";
    String NOTE_INPUT = "XCM701_S001_M007";
    String PRIORITY_CALL_CHECKBOX = "XCM701_S001_H005_1";
    String SEND_BUTTON = "XCM701_S001_B002";

    @Select(REASON_OF_HANDOVER)
    XCM701_S001_EcommPanel selectReasonOfHandover(String reason);

    @TypeInto(CALENDAR_INPUT)
    XCM701_S001_EcommPanel fillDate(String date);

    @TypeInto(value = TELEPHONE_INPUT, clear = true)
    XCM701_S001_EcommPanel fillTelephone(String telephone);

    @TypeInto(NOTE_INPUT)
    XCM701_S001_EcommPanel fillNote(String note);

    @Click(PRIORITY_CALL_CHECKBOX)
    XCM701_S001_EcommPanel clickPriorityCall();

    @Click(SEND_BUTTON)
    STS701_S002_ClientDetailPage clickSend();

    @CustomAction
    default XCM701_S001_EcommPanel checkName(String name) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(name, endpoint.getAttribute(NAME_INPUT, "value"));
        return null;
    }

    @CustomAction
    default XCM701_S001_EcommPanel checkSurname(String surname) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(surname, endpoint.getAttribute(SURNAME_INPUT, "value"));
        return null;
    }

    @CustomAction
    default XCM701_S001_EcommPanel checkInactiveAvailabilityHours() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertNotNull(endpoint.getAttribute(AVAILABILITY_TIME_INPUT,"readonly"), "Element" + AVAILABILITY_TIME_INPUT + "isn't readonly");
        return null;
    }
}