package cz.moneta.test.dsl.forte.pages.brncontrols;

import cz.moneta.test.dsl.forte.FortePageFlow;
import cz.moneta.test.dsl.forte.components.BrnControlsMenu;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.forte.pages.brncontrols.ControlDetail.HOME_TITLE;

@Wait(HOME_TITLE)
public interface ControlDetail extends FortePageFlow<ControlDetail>, BrnControlsMenu {
    String HOME_TITLE = "//title[text()='Kontroly OM | FORTE ']";

    String TRANSACTION_CONTROLS_ADD_BUTTON = "//form[@id='frm-transactionGrid-form']//span[text()='Přidat']";
    String ADD_TRANSACTION_CONTROL_FORM = "//form[@id='frm-newTransactionForm-newTransactionForm']";
    String CONTROL_TYPE_SELECT = ADD_TRANSACTION_CONTROL_FORM + "//select[@id='frmnewTransactionForm-type']";
    String TRANSACTION_DATE_INPUT = ADD_TRANSACTION_CONTROL_FORM + "//input[@id='frmnewTransactionForm-date_transaction']";
    String ACCOUNT_NUMBER_INPUT = ADD_TRANSACTION_CONTROL_FORM + "//input[@id='frmnewTransactionForm-account_number']";
    String TRANSACTION_NUMBER_INPUT = ADD_TRANSACTION_CONTROL_FORM + "//input[@id='frmnewTransactionForm-transaction_number']";
    String TRANSACTION_TYPE_SELECT = ADD_TRANSACTION_CONTROL_FORM + "//select[@id='frmnewTransactionForm-transaction_type']";
    String CONTROL_RESULT_SELECT = ADD_TRANSACTION_CONTROL_FORM + "//select[@id='frmnewTransactionForm-result']";
    String BANKER_SSO_INPUT = ADD_TRANSACTION_CONTROL_FORM + "//input[@id='frmnewTransactionForm-sso_banker']";
    String FIRST_FOUND_BANKER = "//li//div[contains(text(),'%s')]";
    String SUBMIT_BUTTON = ADD_TRANSACTION_CONTROL_FORM + "//input[@name='add']";

    String FIRST_TRANSACTION_DATE = "//form[@id='frm-transactionGrid-form']//tbody//tr//td[3]";

    @Click(value = TRANSACTION_CONTROLS_ADD_BUTTON, andWait = @Wait(CONTROL_TYPE_SELECT))
    ControlDetail clickAddTransactionControl();

    @Select(value = CONTROL_TYPE_SELECT, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    ControlDetail selectControlType(int value);

    @TypeInto(value = TRANSACTION_DATE_INPUT, clear = true)
    @KeyPress(Key.TAB)
    ControlDetail fillTransactionDate(String transactionDate);

    @TypeInto(ACCOUNT_NUMBER_INPUT)
    ControlDetail fillAccountNumber(String account);

    @TypeInto(TRANSACTION_NUMBER_INPUT)
    ControlDetail fillTransactionNumber(String transactionNumber);

    @Select(value = TRANSACTION_TYPE_SELECT, andWait = @Wait(value = SPINNER, until = Until.GONE,by = Lookup.ID))
    ControlDetail selectTransactionType(int value);

    @Select(value = CONTROL_RESULT_SELECT, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    ControlDetail selectControlResult(int value);

    @TypeInto(value = BANKER_SSO_INPUT, andWait = @Wait(explicitWaitSeconds = 3))
    @Click(value = FIRST_FOUND_BANKER, isStringDynamicXpath = true)
    ControlDetail fillBankerSSO(String sso);

    @Click(value = SUBMIT_BUTTON, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    ControlDetail clickSubmit();

    @CheckElementPresent(FIRST_TRANSACTION_DATE)
    ControlsOnOmPage checkFirstTransactionDate(String date);

}