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_SMEPanel.SEND_BUTTON;

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

    String ICO_INPUT = "XCM701_S001_E009";
    String NAME_INPUT = "XCM701_S001_E011";
    String SURNAME_INPUT = "XCM701_S001_E012";
    String NAME_OF_COMPANY_INPUT = "XCM701_S001_E010";
    String MOBILE_INPUT = "XCM701_S001_E015";
    String EMAIL_INPUT = "XCM701_S001_E013";
    String INTEREST_IN_SELECT = "XCM701_S001_C008";
    String NOTE_INPUT = "XCM701_S001_M004";
    String VILLAGE_INPUT = "XCM701_S001_E016";
    String CALENDAR_INPUT = "XCM701_S001_E017";
    String AVAILABILITY_TIME_INPUT = "XCM701_S001_E070";
    String CONTACT_SOURCE_SELECT = "XCM701_S001_C007";
    String SEND_SMS_AND_DOCUMENTS_CHECKBOX = "XCM701_S001_H003_1";
    String CONSENT_101_CHECKBOX = "XCM701_S001_H002_1";
    String SEND_BUTTON = "XCM701_S001_B005";

    @Select(INTEREST_IN_SELECT)
    XCM701_S001_SMEPanel selectInterestIn(String interestIn);

    @Select(CONTACT_SOURCE_SELECT)
    XCM701_S001_SMEPanel selectContactSource(String contactSource);

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

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

    @Click(SEND_SMS_AND_DOCUMENTS_CHECKBOX)
    XCM701_S001_SMEPanel clickSendSMSAndDocuments();

    @Click(CONSENT_101_CHECKBOX)
    @AcceptAlert(waitSecondsForAlert = 5, expectedAlertText = "Přečtěte klientovi souhlas se 101: Souhlasíte s předáním Vašich údajů kolegům, aby Vás mohli kontaktovat?")
    XCM701_S001_SMEPanel clickConsent101();

    @Click(SEND_BUTTON)
    STS701_S002_ClientDetailPage clickSend();

    @CustomAction
    default XCM701_S001_SMEPanel checkActiveIco() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertTrue(endpoint.isElementEnabled(ICO_INPUT));
        return null;
    }

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

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

    @CustomAction
    default XCM701_S001_SMEPanel checkNameOfCompany(String nameOfCompany) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(nameOfCompany, endpoint.getAttribute(NAME_OF_COMPANY_INPUT, "value"));
        return null;
    }

    @TypeInto(value = MOBILE_INPUT, clear = true)
    XCM701_S001_SMEPanel fillMobile(String mobile);

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

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

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