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.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.contactForwarding.panels.XCM701_S001_CarPanel.SEND_BUTTON;

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

    String NAME_INPUT = "XCM701_S001_E019";
    String SURNAME_INPUT = "XCM701_S001_E020";
    String TELEPHONE_INPUT = "XCM701_S001_E022";
    String EMAIL_INPUT = "XCM701_S001_E023";
    String NOTE_INPUT = "XCM701_S001_M002";
    String VILLAGE_INPUT = "XCM701_S001_E025";
    String CALENDAR_INPUT = "XCM701_S001_E026";
    String AVAILABILITY_TIME_INPUT = "XCM701_S001_E050";
    String CONSENT_101_CHECKBOX = "XCM701_S001_H004_1";
    String SEND_BUTTON = "XCM701_S001_B007";

    @TypeInto(value = NOTE_INPUT, clear = true)
    XCM701_S001_CarPanel fillNote(String note);

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

    @TypeInto(TELEPHONE_INPUT)
    XCM701_S001_CarPanel fillTelephone(String telephone);

    @Click(CONSENT_101_CHECKBOX)
    @AcceptAlert(waitSecondsForAlert = 5, expectedAlertText = CONSENT_101_ALERT_TEXT)
    XCM701_S001_CarPanel clickConsent101();

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

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

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

    @CustomAction
    default XCM701_S001_CarPanel checkEmail(String email) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(email, endpoint.getAttribute(EMAIL_INPUT, "value"));
        return null;
    }

    @CustomAction
    default XCM701_S001_CarPanel checkVillage(String village) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(village, endpoint.getAttribute(VILLAGE_INPUT, "value"));
        return null;
    }

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

    @Click(SEND_BUTTON)
    @AcceptAlert(waitSecondsForAlert = 1, expectedAlertText = "Potvrďte prosím souhlas klienta se 101.")
    XCM701_S001_CarPanel clickSendAndCheckExpectedErrorAlert();
}