package cz.moneta.test.dsl.mobile.smartbanking.payment;

import cz.moneta.test.dsl.mobile.smartbanking.SbViewFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.smartbanka.MobilePlatform;
import cz.moneta.test.harness.endpoints.smartbanka.SbEndpoint;
import cz.moneta.test.harness.support.mobile.MobileLookup;
import cz.moneta.test.harness.support.mobile.android.AndroidClick;
import cz.moneta.test.harness.support.mobile.android.AndroidWait;
import cz.moneta.test.harness.support.mobile.ios.IosClick;
import cz.moneta.test.harness.support.mobile.ios.IosWait;
import cz.moneta.test.harness.support.web.CustomAction;

import static cz.moneta.test.dsl.mobile.smartbanking.payment.PaymentSummaryView.IOS_HEADER;
import static cz.moneta.test.dsl.mobile.smartbanking.payment.PaymentSummaryView.TOOLBAR_TITLE;

@AndroidWait(value = TOOLBAR_TITLE, by = MobileLookup.XPATH)
@IosWait(value = IOS_HEADER, by = MobileLookup.IOS_NAME)
public interface PaymentSummaryView extends SbViewFlow<PaymentSummaryView>, StoreAccessor {
    String TOOLBAR_TITLE = "//android.widget.TextView[contains(@resource-id, 'id/toolbar_title') and @text='Kontrola údajů']";
    String FROM_ACCOUNT = "txt_info_second_row";
    String TO_ACCOUNT = "txt_info_row_value";
    String AMOUNT = "txt_money_row_amount";
    String DATE = "txt_info_row_value";
    String VARIABLE_SYMBOL = "txt_info_row_value";
    String SENT_BUTTON = "btn_send_payment";

    String IOS_HEADER = "Kontrola údajů";
    String IOS_FROM_ACCOUNT = "ACCOUNT_NUMBER";
    String IOS_TO_ACCOUNT = "//XCUIElementTypeCell[contains(@name, 'Na účet')]/XCUIElementTypeOther[1]/XCUIElementTypeStaticText";
    String IOS_AMOUNT = "//XCUIElementTypeApplication[@name='TEST']/XCUIElementTypeWindow[1]/XCUIElementTypeOther[2]/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[3]/XCUIElementTypeStaticText";
    String IOS_VARIABLE_SYMBOL = "//XCUIElementTypeCell[contains(@name, 'Variabilní symbol')]/XCUIElementTypeOther[1]/XCUIElementTypeStaticText";
    String IOS_SENT_BUTTON = "Pokračovat";

    @CustomAction
    default PaymentSummaryView checkPaymentData(StoreAccessor store, Payment payment){
        SbEndpoint endpoint = getEndpoint(SbEndpoint.class);
        if (MobilePlatform.isAndroid(store)) {
            endpoint.checkElementContent(FROM_ACCOUNT, payment.getFromAccountWithBankCode());
            endpoint.checkElementContent(TO_ACCOUNT, payment.getToAccountWithBankCode());
            endpoint.checkElementContent(AMOUNT, payment.getAmount());
            endpoint.checkElementContent(VARIABLE_SYMBOL, payment.getVariableSymbol());
        }else {
            endpoint.checkElementContent(IOS_FROM_ACCOUNT, payment.getFromAccountWithBankCode());
            endpoint.checkElementContent(IOS_TO_ACCOUNT, payment.getToAccountWithBankCode(), MobileLookup.XPATH);
            endpoint.checkElementContent(IOS_AMOUNT, payment.getAmount(), MobileLookup.XPATH);
            endpoint.checkElementContent(IOS_VARIABLE_SYMBOL, payment.getVariableSymbol(), MobileLookup.XPATH);
        }
        return null;
    }

//    //example of using containers
//    @AndroidCheckElementContents({
//            @AndroidCheckElementContent(FROM_ACCOUNT),
//            @AndroidCheckElementContent(TO_ACCOUNT),
//            @AndroidCheckElementContent(AMOUNT),
//            @AndroidCheckElementContent(VARIABLE_SYMBOL)})
//    @IosCheckElementContents({
//            @IosCheckElementContent(IOS_FROM_ACCOUNT),
//            @IosCheckElementContent(IOS_TO_ACCOUNT),
//            @IosCheckElementContent(IOS_AMOUNT),
//            @IosCheckElementContent(IOS_VARIABLE_SYMBOL)})
//    PaymentSummaryView checkPaymentData(String fromAccount, String toAccount, String amount, String variableSymbol);

    @AndroidClick(value = SENT_BUTTON)
    @IosClick(IOS_SENT_BUTTON)
    CertificationPaymentView certifyButton();
}

