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

import cz.moneta.test.dsl.ufo.operations.shared.topmenu.XXX702_SharedTopMenu;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;


import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.TRA740_S001_CreateNewTransferPaymentOrderPage.PAGE_FIELDSET;

@Wait(PAGE_FIELDSET)
@Wait(value = LOAD_IMG_DIV_CLASS, until = Until.GONE, by = Lookup.CLASSNAME)
public interface TRA740_S001_CreateNewTransferPaymentOrderPage extends WebFlow<TRA740_S001_CreateNewTransferPaymentOrderPage>, XXX702_SharedTopMenu<TRA740_S001_CreateNewTransferPaymentOrderPage>, StoreAccessor {

    String ID_PAYMENT_ORDER_KEY = "ID_PAYMENT_ORDER";
    String PAGE_FIELDSET = "TRA740_S001_Y001";
    String BACK_OFFICE_ZAKLAD_RADIO = "TRA740_S001_R001_BackOfficeZaklad";
    String PAYMENTS_ZAKLAD_RADIO = "TRA740_S001_R001_PaymentsZaklad";
    String ATM_RADIO = "TRA740_S001_R002_ATM";
    String ORDER_TYPE_SELECT = "TRA740_S001_C001";
    String PAYER_ACCOUNT_NUMBER_INPUT = "TRA740_S001_E001";
    String RECIPIENT_ACCOUNT_NUMBER_INPUT = "TRA740_S001_E003";

    String AMOUNT_INPUT = "TRA740_S001_E005";

    String SEND_BUTTON = "TRA740_S001_B001";
    String TRANSACTION_SUCCESSFULLY_ESTABLISHED_DIV = "XXX702_T001_L107";
    String ID_PAYMENT_ORDER_DIV = "XXX702_T001_L107";
    String VARIABLE_SYMBOL = "TRA740_S001_E007";
    String SPECIFICALLY_SYMBOL = "TRA740_S001_E009";
    String MESSAGE = "TRA740_S001_M001";

    @Click(value = BACK_OFFICE_ZAKLAD_RADIO, jsClick = true, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    TRA740_S001_CreateNewTransferPaymentOrderPage clickBackOfficeZaklad();

    @Click(value = PAYMENTS_ZAKLAD_RADIO, jsClick = true, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    TRA740_S001_CreateNewTransferPaymentOrderPage clickPaymentsZaklad();

    @Click(value = ATM_RADIO, jsClick = true, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    TRA740_S001_CreateNewTransferPaymentOrderPage clickATM();

    @Select(value = ORDER_TYPE_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    TRA740_S001_CreateNewTransferPaymentOrderPage selectOrderType(String orderType);

    @TypeInto(value = PAYER_ACCOUNT_NUMBER_INPUT, clear = true, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    TRA740_S001_CreateNewTransferPaymentOrderPage fillPayerAccountNumber(String accountNumber);

    @TypeInto(value = RECIPIENT_ACCOUNT_NUMBER_INPUT, clear = true)
    @Click(value = AMOUNT_INPUT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, explicitWaitSeconds = 1))
    TRA740_S001_CreateNewTransferPaymentOrderPage fillRecipientAccountNumber(String accountNumber);

    @TypeInto(value = AMOUNT_INPUT, clear = true)
    TRA740_S001_CreateNewTransferPaymentOrderPage fillAmount(String amount);

    @TypeInto(value = VARIABLE_SYMBOL, clear = true)
    TRA740_S001_CreateNewTransferPaymentOrderPage fillVariableSymbol(String variableSymbol);

    @TypeInto(value = SPECIFICALLY_SYMBOL, clear = true)
    TRA740_S001_CreateNewTransferPaymentOrderPage fillSpecificallySymbol(String specificallySymbol);

    @TypeInto(value = MESSAGE, clear = true)
    TRA740_S001_CreateNewTransferPaymentOrderPage fillMessage(String message);

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

    @CheckElementContent(TRANSACTION_SUCCESSFULLY_ESTABLISHED_DIV)
    TRA740_S001_CreateNewTransferPaymentOrderPage checkTransactionSuccessfullyEstablished(String content);

    @CustomAction
    default TRA740_S001_CreateNewTransferPaymentOrderPage saveTaskIDPaymentOrder() {

        UfoEndpoint endpoint = this.getEndpoint(UfoEndpoint.class);
        String establishedTaskText = endpoint.getText(ID_PAYMENT_ORDER_DIV).replaceAll(".*ID: (\\d+)$", "$1");
        this.store(ID_PAYMENT_ORDER_KEY, establishedTaskText);
        return null;
    }

    @Click(value = SEND_BUTTON)
    @AcceptAlert(waitSecondsForAlert = 10, expectedAlertText = "Údaj TRA740_S001_E005 je zadán chybně - zadejte znovu. [TRA740_S001_E005]")
    TRA740_S001_CreateNewTransferPaymentOrderPage clickSendAndAcceptAlert();

}