package cz.moneta.test.dsl.ib.accountsandtransactions.directdebitorder;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.data.GeneratorType;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.TypeInto;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.ib.accountsandtransactions.directdebitorder.DirectDebitCreatePage.CONTINUE_BUTTON;

@Wait(value = CONTINUE_BUTTON)
public interface DirectDebitCreatePage extends IbPageFlow<DirectDebitCreatePage>, StoreAccessor {
    String FROM_FIRST_ACCOUNT_SELECT = "//select[@id='fromAccount']//option[position() = 1]";
    String PARTNER_ACCOUNT_NUMBER = "//input[@name='partnerAccountNumber']";
    String PARTNER_ACCOUNT_BANK = "//input[@name='partnerAccountBank']";
    String USER_NOTE = "//input[@id='userNote']";
    String DIRECT_DEBIT_LIMIT = "//input[@id='amount']";
    String END_DATE = "//input[@id='endDate']";
    String CONTINUE_BUTTON = "//img[@alt='Pokračovat']";

    @Click(FROM_FIRST_ACCOUNT_SELECT)
    DirectDebitCreatePage clickFromAccountSelect();

    @CustomAction
    default DirectDebitCreatePage getAndFillAccountFromNumber() {
        IbEndpoint endpoint = getEndpoint(IbEndpoint.class);
        String value = endpoint.getAttribute(FROM_FIRST_ACCOUNT_SELECT, "value");
        String partnerAccountNo = generate(GeneratorType.ACCOUNT_NUMBER, value);
        endpoint.type(() -> PARTNER_ACCOUNT_NUMBER, partnerAccountNo, false);
        return null;
    }

    @TypeInto(PARTNER_ACCOUNT_BANK)
    DirectDebitCreatePage fillToAccountBank(String toAccountBank);

    @TypeInto(USER_NOTE)
    DirectDebitCreatePage fillUserNote(String userNote);

    @TypeInto(DIRECT_DEBIT_LIMIT)
    DirectDebitCreatePage fillDirectDebitLimit(String incassoLimit);

    @TypeInto(END_DATE)
    DirectDebitCreatePage fillEndDate(String endDate);

    @Click(CONTINUE_BUTTON)
    DirectDebitAuthorizePage clickContinueButton();
}