package cz.moneta.test.dsl.ufo.operations.client.clientDetail;

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.shared.SharedElements.LOAD_IMG_DIV_CLASS;

public interface STS701_S002_InfoServiceOrderDetail extends StoreAccessor {

    String SAVE_BUTTON = "STS701_S002_B078";
    String SMS_IN_DETAIL_OF_ORDER_RADIO = "STS701_S002_R003_SMS";
    String TELEPHONE_IN_DETAIL_OF_ORDER_INPUT = "STS701_S002_E017";
    String EMAIL_DETAIL_OF_ORDER_RADIO = "STS701_S002_R003_Email";
    String EMAIL_INPUT_DETAIL_OF_ORDER_INPUT = "STS701_S002_E021";
    String FROM_BALANCE_INPUT = "STS701_S002_E020";
    String START_TIME_IN_DETAIL_OF_ORDER_COMBOBOX = "STS701_S002_C020";
    String END_TIME_IN_DETAIL_OF_ORDER_COMBOBOX = "STS701_S002_C021";

    @Click(value = SAVE_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STS701_S002_AdcProductsPanel clickSave();

    @Click(SMS_IN_DETAIL_OF_ORDER_RADIO)
    STS701_S002_AdcProductsPanel clickSmsInDetailOfOrder();

    @Wait(value = TELEPHONE_IN_DETAIL_OF_ORDER_INPUT, until = Until.VISIBLE)
    @TypeInto(TELEPHONE_IN_DETAIL_OF_ORDER_INPUT)
    STS701_S002_AdcProductsPanel fillTelephoneInputInDetailOfOrder(String telephone);

    @Click(EMAIL_DETAIL_OF_ORDER_RADIO)
    STS701_S002_AdcProductsPanel clickEmailInDetailOfOrder();

    @TypeInto(value = EMAIL_INPUT_DETAIL_OF_ORDER_INPUT, clear = true)
    STS701_S002_AdcProductsPanel fillEmailInputDetailOfOrder(String email);

    @TypeInto(value = FROM_BALANCE_INPUT, clear = true)
    STS701_S002_AdcProductsPanel fillBalanceFrom(String fromBalance);

    @Wait(value = START_TIME_IN_DETAIL_OF_ORDER_COMBOBOX, until = Until.VISIBLE)
    @Select(START_TIME_IN_DETAIL_OF_ORDER_COMBOBOX)
    STS701_S002_AdcProductsPanel selectStartTimeInDetailOfOrder(String startTime);

    @Wait(value = START_TIME_IN_DETAIL_OF_ORDER_COMBOBOX, until = Until.VISIBLE)
    @Select(END_TIME_IN_DETAIL_OF_ORDER_COMBOBOX)
    STS701_S002_AdcProductsPanel selectEndTimeInDetailOfOrder(String endTime);

    @Wait(value = START_TIME_IN_DETAIL_OF_ORDER_COMBOBOX, until = Until.VISIBLE)
    @CheckElementContent(START_TIME_IN_DETAIL_OF_ORDER_COMBOBOX)
    STS701_S002_AdcProductsPanel checkStartTimeDetailOfOrder(String startTime);

    @Wait(value = END_TIME_IN_DETAIL_OF_ORDER_COMBOBOX, until = Until.VISIBLE)
    @CheckElementContent(END_TIME_IN_DETAIL_OF_ORDER_COMBOBOX)
    STS701_S002_AdcProductsPanel checkEndTimeDetailOfOrder(String endTime);

    @CustomAction
    default STS701_S002_AdcProductsPanel checkTelephoneInDetailOfOrderInput(String telephone) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(telephone, endpoint.getAttribute(TELEPHONE_IN_DETAIL_OF_ORDER_INPUT, "value"));
        return null;
    }

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

    @CustomAction
    default STS701_S002_AdcProductsPanel checkBalance(String balance) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertEquals(balance, endpoint.getAttribute(FROM_BALANCE_INPUT, "value"));
        return null;
    }
}
