package cz.moneta.test.dsl.ufo.banka.pages.main.adc;

import cz.moneta.test.dsl.ufo.banka.pages.common.pages.INK001_OBR001_004_ConfirmationPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.TIS051_S001_DispositionGeneratePage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.CheckElementContent;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Lookup;
import cz.moneta.test.harness.support.web.Select;
import cz.moneta.test.harness.support.web.TypeInto;
import cz.moneta.test.harness.support.web.Wait;
import cz.moneta.test.harness.support.web.WebFlow;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ufo.banka.pages.main.adc.ADC026_S001_BankApiDetailPage.SAVE_BUTTON;

@Wait(SAVE_BUTTON)
public interface ADC026_S001_BankApiDetailPage extends WebFlow<ADC026_S001_BankApiDetailPage>, StoreAccessor {

    String SAVE_BUTTON = "ADC026_S001_B001";
    String DAILY_LIMIT_INPUT = "ADC026_S001_E023";
    String THIRD_PARTY_SELECT = "ADC026_S001_C001";
    String ACCOUNT_SELECT = "ADC026_S001_C002";
    String ADD_BUTTON = "ADC026_S001_B003";
    String DEACTIVATE_BUTTON = "ADC026_S001_B004";
    String HISTORY_BUTTON = "ADC026_S001_B005";
    String HISTORY_CALL_BUTTON = "ADC026_S001_B006";
    String THIRD_PARTY_TABLE_NAME_PATH = "//*[@id='ADC026_S001_G001_UfoTable']/tbody/tr/td[2]";
    String THIRD_PARTY_TABLE_NUMBER_PATH = "//*[@id='ADC026_S001_G001_UfoTable']/tbody/tr/td[3]";
    String THIRD_PARTY_TABLE_ACCOUNT_PATH = "//*[@id='ADC026_S001_G001_UfoTable']/tbody/tr/td[4]";
    String THIRD_PARTY_TABLE_ACTIVE_FROM_PATH = "//*[@id='ADC026_S001_G001_UfoTable']/tbody/tr/td[5]";
    String THIRD_PARTY_TABLE_HISTORY_NAME_PATH = "//*[@id='ADC026_S001_G002_UfoTable']/tbody/tr/td[1]";
    String THIRD_PARTY_TABLE_HISTORY_NUMBER_PATH = "//*[@id='ADC026_S001_G002_UfoTable']/tbody/tr/td[2]";
    String THIRD_PARTY_TABLE_HISTORY_ACCOUNT_PATH = "//*[@id='ADC026_S001_G002_UfoTable']/tbody/tr/td[3]";
    String THIRD_PARTY_TABLE_HISTORY_ACTIVE_FROM_PATH = "//*[@id='ADC026_S001_G002_UfoTable']/tbody/tr/td[4]";
    String THIRD_PARTY_TABLE_HISTORY_ACTIVE_TO_PATH = "//*[@id='ADC026_S001_G002_UfoTable']/tbody/tr/td[5]";
    String THIRD_PARTY_TABLE_FIRST_ROW_RADIO = "ADC026_S001_G001-0";
    String THIRD_PARTY_TABLE_HISTORY_CLOSE = "ADC026_S001_P001";
    String THIRD_PARTY_ACTIVE_DATE_FROM = "THIRD_PARTY_ACTIVE_DATE_FROM";
    String THIRD_PARTY_HISTORY_DATE_FROM = "THIRD_PARTY_HISTORY_DATE_FROM";
    String THIRD_PARTY_HISTORY_DATE_TO = "THIRD_PARTY_HISTORY_DATE_TO";

    @Click(SAVE_BUTTON)
    TIS051_S001_DispositionGeneratePage saveLimitBanApi();

    @TypeInto(value = DAILY_LIMIT_INPUT, clear = true)
    ADC026_S001_BankApiDetailPage fillDailyLimit(String dailyLimit);

    @Select(THIRD_PARTY_SELECT)
    ADC026_S001_BankApiDetailPage selectThirdParty(String thirdParty);

    @Select(ACCOUNT_SELECT)
    ADC026_S001_BankApiDetailPage selectAccount(String account);

    @Click(ADD_BUTTON)
    INK001_OBR001_004_ConfirmationPage activateCisp();

    @Click(ADD_BUTTON)
    ADC026_S001_BankApiDetailPage activateCispValidationMessage();

    @Click(DEACTIVATE_BUTTON)
    INK001_OBR001_004_ConfirmationPage deactivateCisp();

    @Click(DEACTIVATE_BUTTON)
    ADC026_S001_BankApiDetailPage deactivateCispValidationMessage();

    @Click(HISTORY_BUTTON)
    ADC026_S001_BankApiDetailPage historyCispSettings();

    @Click(HISTORY_CALL_BUTTON)
    ADC026_S001_BankApiDetailPage historyCallCisp();

    @CheckElementContent(value = THIRD_PARTY_TABLE_HISTORY_NAME_PATH, by = Lookup.XPATH)
    ADC026_S001_BankApiDetailPage checkHistoryTableName(String thirdPartyName);

    @CheckElementContent(value = THIRD_PARTY_TABLE_HISTORY_NUMBER_PATH, by = Lookup.XPATH)
    ADC026_S001_BankApiDetailPage checkHistoryTableNumber(String thirdPartyNumber);

    @CheckElementContent(value = THIRD_PARTY_TABLE_HISTORY_ACCOUNT_PATH, by = Lookup.XPATH)
    ADC026_S001_BankApiDetailPage checkHistoryTableAccount(String account);

    @CustomAction
    default ADC026_S001_BankApiDetailPage checkAlertAndAcceptActivation() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String alertText = endpoint.getAlertText(60);
        endpoint.acceptAlert(20);
        Assertions.assertEquals("Vazba třetí strany a účtu již existuje, nelze přidat.", alertText);
        return null;
    }

    @CustomAction
    default ADC026_S001_BankApiDetailPage checkAlertAndAcceptDeactivate() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String alertText = endpoint.getAlertText(60);
        endpoint.acceptAlert(20);
        Assertions.assertEquals("Není vybrána žádná vazba. Vyberte požadovanou položku.", alertText);
        return null;
    }

    @CustomAction
    default ADC026_S001_BankApiDetailPage storeThirdPartyDateFrom() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        store(THIRD_PARTY_ACTIVE_DATE_FROM, endpoint.getText(THIRD_PARTY_TABLE_ACTIVE_FROM_PATH, Lookup.XPATH));
        return null;
    }

    @CustomAction
    default ADC026_S001_BankApiDetailPage storeThirdPartyHistoryDates() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        store(THIRD_PARTY_HISTORY_DATE_FROM, endpoint.getText(THIRD_PARTY_TABLE_HISTORY_ACTIVE_FROM_PATH, Lookup.XPATH));
        store(THIRD_PARTY_HISTORY_DATE_TO, endpoint.getText(THIRD_PARTY_TABLE_HISTORY_ACTIVE_TO_PATH, Lookup.XPATH));
        return null;
    }

    @Click(THIRD_PARTY_TABLE_FIRST_ROW_RADIO)
    ADC026_S001_BankApiDetailPage selectFirstRow();

    @CheckElementContent(value = THIRD_PARTY_TABLE_NAME_PATH, by = Lookup.XPATH)
    ADC026_S001_BankApiDetailPage checkThirdPartyTableName(String thirdPartyName);

    @CheckElementContent(value = THIRD_PARTY_TABLE_NUMBER_PATH, by = Lookup.XPATH)
    ADC026_S001_BankApiDetailPage checkThirdPartyTableNumber(String thirdPartyNumber);

    @CheckElementContent(value = THIRD_PARTY_TABLE_ACCOUNT_PATH, by = Lookup.XPATH)
    ADC026_S001_BankApiDetailPage checkThirdPartyTableAccount(String account);

    @Click(THIRD_PARTY_TABLE_HISTORY_CLOSE)
    ADC026_S001_BankApiDetailPage closeThirdPartyHistory();
}