package cz.moneta.test.dsl.payment_engine.home;

import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_administration.PaymentEngineParametersChannelParameters;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_administration.PaymentEngineXctRoutingTable;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_cache24_7.PaymentsEngineCache24Menu;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_clients.*;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_monitoring.PaymentEngineMonitoringChannelInstances;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_monitoring.PaymentEngineMonitoringChannelList;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_monitoring.PaymentEngineMonitoringProcessList;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_search.PaymentEngineSearchPage;
import cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_transaction.*;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.payment_engine.PaymentEngineEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.payment_engine.home.PaymentEngineHomePage.*;

@Wait({SUPERVIZOR, MONITORING, SEARCH, TRANSACTION, CLIENTS, ADMINISTRATION, CACHE24_7})
public interface PaymentEngineHomePage extends WebFlow<PaymentEngineHomePage>, StoreAccessor {
    String SUPERVIZOR = "//button[text() = 'Supervizor']";
    String MONITORING = "//button[text() = 'Monitoring']";
    String SEARCH = "//button[text() = 'Vyhledávání']";
    String TRANSACTION = "//button[text() = 'Transakce']";
    String FEES = "//button[text() = 'Poplatky']";
    String CLIENTS = "//button[text() = 'Klienti']";
    String ADMINISTRATION = "//button[text() = 'Administrace']";
    String CACHE24_7 = "//button[text() = 'Cache 24/7']";
    String MANUAL_CREATE = "//a[text()='Manuální založení']";
    String OUTGOING_SCT = "//a[text()='Založit SCT platbu']";
    String OUTGOING_XCT_CLIENT_PAYMENT = "//a[text()='Založit odchozí XCT klientskou platbu']";
    String CHANNEL_MONITORING = "//a[text()='Monitor kanálů']";
    String CHANNEL_LIST = "//a[text()='Seznam kanálů']";
    String CHANNEL_INSTANCES = "//a[text()='Instance kanálů']";
    String PARAMETERS = "//a[text()='Parametry']";
    String CHANNEL_PARAMETERS = "//a[text()='Parametry kanálů']";
    String TRANSACTIONS_ROUTING = "//a[text()='Směrování transakcí']";
    String XCT_ROUTING_TABLE = "//a[text()='XCT Routing table']";
    String PROCESS_MONITORING = "//a[text()='Monitor procesů']";
    String PROCESS_LIST = "//a[text()='Seznam procesů']";
    String INGOING = "//a[text()='Příchozí']";
    String OUTGOING = "//a[text()='Odchozí']";
    String DOMESTIC = "//a[text()='Domácí']";
    String SEPA = "//a[text()='SEPA']";
    String XCT = "//a[text()='XCT']";
    String DISTRIBUTION_TO_CLEARING = "//a[text()='Distribuce do clearingu']";
    String WAITING = "//div[@class='x-layer x-menu'][contains(@style,'visible')]//a[text()='Čekající']";
    String MANUAL = "//div[@class='x-layer x-menu'][contains(@style,'visible')]//a[text()='Manuální']";
    String FOR_VERIFICATION = "//div[@class='x-layer x-menu'][contains(@style,'visible')]//a[text()='Ke schválení']";
    String ARCHIV = "//div[@class='x-layer x-menu'][contains(@style,'visible')]//a[text()='Archiv']";
    String CREATE_INSTANT_PAYMENT = "//a[text()='Založit okamžitou platbu']";
    String CREATE_DOMESTIC_PAYMENT = "//a[text()='Založit domácí platbu']";
    String CREATE_XCT_FI2FI_PAYMENT = "//a[text()='Založit odchozí XCT FI2FI platbu']";
    String CREATE_IFCY_PAYMENT = "//a[text()='Založit interní platbu IFCY']";
    String CREATE_SCT_CLAIM_NON_RECEIPT = "//a[text()='Založit SCT Claim Non-Receipt']";
    String STANDING_ORDER = "//a[text()='Trvalé příkazy']";
    String CREATE_STANDING_ORDER_CZ = "//a[text()='Nový trvalý příkaz CZ']";
    String LIST_OF_STANDING_ORDERS = "//a[text()='Seznam']";
    String LIST_OF_CLIENTS = "//a[text()='Klienti']";
    String LIST_OF_CLIENTS_ACCOUNTS = "//a[text()='Klientské účty']";

    @Wait(explicitWaitSeconds = 3)
    PaymentEngineHomePage wait3sec();

    @Wait(value = SEARCH, until = Until.VISIBLE)
    @Click(SEARCH)
    PaymentEngineSearchPage search();

    @Click(CACHE24_7)
    PaymentsEngineCache24Menu clickOnCache24_7();

    @Click(CLIENTS)
    PaymentEngineClientsMenu clickOnClients();

    @CustomAction
    default void clickOnSubItem(String partOfMenuXpath, String itemXpath, String subItemXpath) {
        PaymentEngineEndpoint endpoint = getEndpoint(PaymentEngineEndpoint.class);
        endpoint.click(() -> partOfMenuXpath);
        endpoint.moveToElementAndClickToOtherElement(itemXpath, subItemXpath);
    }

    @CustomAction
    default void clickOnSubItem(String partOfMenuXpath, String itemXpath, String subItemXpath, String subSubItemXpath) {
        PaymentEngineEndpoint endpoint = getEndpoint(PaymentEngineEndpoint.class);
        endpoint.click(() -> partOfMenuXpath);
        endpoint.moveToElement(itemXpath);
        endpoint.waitForElementsToLoad(3, Until.VISIBLE, subItemXpath);
        endpoint.moveToElementAndClickToOtherElement(subItemXpath, subSubItemXpath);
    }

    @CustomAction
    default PaymentEngineManualCreateOutgoingSctPage clickTransactionAndChooseCreateSctFromCreateManualMenu() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, SEPA, OUTGOING_SCT);
        return null;
    }

    @CustomAction
    default PaymentEngineManualCreateOutgoingXctClientPaymentPage clickTransactionAndChooseCreateXctClientPaymentFromCreateManualMenu() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, XCT, OUTGOING_XCT_CLIENT_PAYMENT);
        return null;
    }

    @CustomAction
    default PaymentEngineManualForVerificationPage clickTransactionAndChooseForVerificationFromCreateManualMenu() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, FOR_VERIFICATION);
        return null;
    }

    @CustomAction
    default PaymentEngineMonitoringChannelList clickMonitoringAndChooseChannelListFromChanelMonitoring() {
        clickOnSubItem(MONITORING, CHANNEL_MONITORING, CHANNEL_LIST);
        return null;
    }

    @CustomAction
    default PaymentEngineMonitoringChannelInstances clickMonitoringAndChooseChannelInstanceFromChanelMonitoring() {
        clickOnSubItem(MONITORING, CHANNEL_MONITORING, CHANNEL_INSTANCES);
        return null;
    }

    @CustomAction
    default PaymentEngineMonitoringProcessList clickMonitoringAndChooseProcessListFromProcessMonitoring() {
        clickOnSubItem(MONITORING, PROCESS_MONITORING, PROCESS_LIST);
        return null;
    }

    @CustomAction
    default PaymentEngineParametersChannelParameters clickAdministrationAndChooseChannelParametersFromParameters() {
        clickOnSubItem(ADMINISTRATION, PARAMETERS, CHANNEL_PARAMETERS);
        return null;
    }

    @CustomAction
    default PaymentEngineXctRoutingTable clickAdministrationAndChooseXCTRoutingTableFromTransactionsRouting() {
        clickOnSubItem(ADMINISTRATION, TRANSACTIONS_ROUTING, XCT_ROUTING_TABLE);
        return null;
    }

    @CustomAction
    default PaymentEngineIngoingArchiv clickTransactionAndChooseArchivFromIngoing() {
        clickOnSubItem(TRANSACTION, INGOING, ARCHIV);
        return null;
    }

    @CustomAction
    default PaymentEngineIngoingWaiting clickTransactionAndChooseWaitingFromIngoing() {
        clickOnSubItem(TRANSACTION, INGOING, WAITING);
        return null;
    }

    @CustomAction
    default PaymentEngineIngoingForVerification clickTransactionAndChooseForVerificationFromIngoing() {
        clickOnSubItem(TRANSACTION, INGOING, FOR_VERIFICATION);
        return null;
    }

    @CustomAction
    default PaymentEngineOutgoingManual clickTransactionAndChooseManualFromOutgoing() {
        clickOnSubItem(TRANSACTION, OUTGOING, MANUAL);
        return null;
    }

    @CustomAction
    default PaymentEngineOutgoingForVerification clickTransactionAndChooseForVerificationFromOutgoing() {
        clickOnSubItem(TRANSACTION, OUTGOING, FOR_VERIFICATION);
        return null;
    }

    @CustomAction
    default PaymentEngineOutgoingArchiv clickTransactionAndChooseArchivFromOutgoing() {
        clickOnSubItem(TRANSACTION, OUTGOING, ARCHIV);
        return null;
    }

    @CustomAction
    default PaymentEngineDistributionToClearingArchiv clickTransactionAndChooseArchivFromDistributionToClearing() {
        clickOnSubItem(TRANSACTION, DISTRIBUTION_TO_CLEARING, ARCHIV);
        return null;
    }

    @CustomAction
    default PaymentEngineDistributionToClearingForVerification clickTransactionAndChooseForVerificationFromDistributionToClearing() {
        clickOnSubItem(TRANSACTION, DISTRIBUTION_TO_CLEARING, FOR_VERIFICATION);
        return null;
    }

    @CustomAction
    default PaymentEngineCreateInstantPayment clickTransactionAndChooseCreateInstantPaymentFromManualCreate() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, DOMESTIC, CREATE_INSTANT_PAYMENT);
        return null;
    }

    @CustomAction
    default PaymentEngineCreateDomesticPayment clickTransactionAndChooseCreateDomesticPaymentFromManualCreate() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, DOMESTIC, CREATE_DOMESTIC_PAYMENT);
        return null;
    }

    @CustomAction
    default PaymentEngineCreateXctFI2FIPayment clickTransactionAndChooseCreateXctFI2FIPaymentFromManualCreate() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, XCT, CREATE_XCT_FI2FI_PAYMENT);
        return null;
    }

    @CustomAction
    default PaymentEngineCreateInhouseIfcyPayment clickTransactionAndChooseCreateInhouseIfcyPaymentFromManualCreate() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, DOMESTIC, CREATE_IFCY_PAYMENT);
        return null;
    }

    @CustomAction
    default PaymentEngineManualCreateSCTClaimNonReciept clickTransactionAndChooseCreateCreateSCTClaimNonReceipt() {
        clickOnSubItem(TRANSACTION, MANUAL_CREATE, SEPA, CREATE_SCT_CLAIM_NON_RECEIPT);
        return null;
    }

    @CustomAction
    default PaymentEngineClientsStandingOrderCZ clickClientsAndChooseCreateCzStandingOrderFromStandingOrders() {
        clickOnSubItem(CLIENTS, STANDING_ORDER, CREATE_STANDING_ORDER_CZ);
        return null;
    }

    @CustomAction
    default PaymentEngineClientsListOfStandingOrders clickClientsAndChooseListOfStandingOrderFromStandingOrders() {
        clickOnSubItem(CLIENTS, STANDING_ORDER, LIST_OF_STANDING_ORDERS);
        return null;
    }

    @CustomAction
    default PaymentEngineClientsListOfClients clickClientsAndChooseListOfClients() {
        clickOnSubItem(CLIENTS, CLIENTS, LIST_OF_CLIENTS);
        return null;
    }

    @CustomAction
    default PaymentEngineClientsListOfClientsAccounts clickClientsAndChooseListOfClientsAccounts() {
        clickOnSubItem(CLIENTS, CLIENTS, LIST_OF_CLIENTS_ACCOUNTS);
        return null;
    }
}