package cz.moneta.test.dsl.newib.payments;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.newib.payments.BulkPaymentPage.*;

@Wait(value = {DETAIL_INFORMATION_XPATH, FROM_ACCOUNT_TEXT_XPATH, CONTINUE_BTN_XPATH}, waitSecondsForElement = 30)
public interface BulkPaymentPage extends NewIbPageFlow<BulkPaymentPage>, StoreAccessor {

    String DETAIL_INFORMATION_XPATH = "//span[contains(text(), 'Symboly, zpráva pro příjemce, poznámka a další')]";
    String FROM_ACCOUNT_TEXT_XPATH = "//label[@for='sourceAccountId_button'][text()='Z účtu']";
    String ACCOUNT_NUMBER_INPUT_XPATH = "//input[@id='destinationAccountNumber']";
    String BANK_CODE_INPUT_XPATH = "//input[@name='destinationAccountBank']";
    String AMOUNT_INPUT_XPATH = "//input[@name='amount']";
    String VARIABLE_SYMBOL_INPUT_XPATH = "//input[@name='variableSymbol']";
    String CONSTANT_SYMBOL_INPUT_XPATH = "//input[@name='constantSymbol']";
    String SPECIFIC_SYMBOL_INPUT_XPATH = "//input[@name='specificSymbol']";
    String MESSAGE_RECIPIENT_INPUT_XPATH = "//textarea[@name='noteForRecipient']";
    String PAYER_NOTE_INPUT_XPATH = "//textarea[@name='noteForPayer']";
    String ADD_ANOTHER_PAYMENT_BTN_XPATH = "//button[@data-testid='bulk-payment-add']";
    String CONTINUE_BTN_XPATH = "//button[@data-testid='bulk-payment-continue']";
    String BANK_CODE_SELECT_XPATH = "//div[@data-testid='destinationAccountBank-select']";

    @TypeInto(ACCOUNT_NUMBER_INPUT_XPATH)
    BulkPaymentPage setAccountNumber(String accountNumber);

    @CustomAction
    default BulkPaymentPage setBankCode(String bankCode) {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        newIbEndpoint.click(() -> BANK_CODE_SELECT_XPATH);
        newIbEndpoint.type(() -> BANK_CODE_INPUT_XPATH, bankCode, true);
        newIbEndpoint.sendKeysOneAtATime(Key.ENTER);
        return null;
    }

    @TypeInto(AMOUNT_INPUT_XPATH)
    BulkPaymentPage setAmount(String amount);

    @TypeInto(VARIABLE_SYMBOL_INPUT_XPATH)
    BulkPaymentPage setVariableSymbol(String variableSymbol);

    @TypeInto(CONSTANT_SYMBOL_INPUT_XPATH)
    BulkPaymentPage setConstantSymbol(String constantSymbol);

    @TypeInto(SPECIFIC_SYMBOL_INPUT_XPATH)
    BulkPaymentPage setSpecificSymbol(String specificSymbol);

    @TypeInto(MESSAGE_RECIPIENT_INPUT_XPATH)
    BulkPaymentPage setRecipientMessage(String recipientMessage);

    @TypeInto(PAYER_NOTE_INPUT_XPATH)
    BulkPaymentPage setPayerNote(String payerNote);

    @Click(value =  ADD_ANOTHER_PAYMENT_BTN_XPATH, andWait = @Wait(value = CONTINUE_BTN_XPATH, waitSecondsForElement = 10, until = Until.CLICKABLE))
    BulkPaymentPage clickOnAddPayment();

    @Click(CONTINUE_BTN_XPATH)
    BulkPaymentSummaryPage clickOnContinue();
}
