package cz.moneta.test.dsl.ufo.operations.client.product;

import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_AdcProductsPanel;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.Assert;

import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

@Wait(value = ADC739_S001_IBSBPage.CLIENTS_NAME, until = Until.VISIBLE)
public interface ADC739_S001_IBSBPage extends WebFlow<ADC739_S001_IBSBPage>, StoreAccessor {

    String DETAIL_EDISPONENT = "ADC739_S001_P001-1";
    String CLIENTS_NAME = "ADC739_S001_L004-1";
    String SEND_LOGIN_PASSWORD_SMS = "ADC739_S001_B003";
    String STATUS_BAR = "XXX702_T001_L107";
    String REQUIREMENT_BUTTON_XPATH = "//*[@id=\"XXX702_T001_V002\"]/div[2]/div/div[5]/div/button";
    String REFRESH_REQUIREMENT_BUTTON = "XXX702_T001_B001";
    String REQUIREMENT_DESCRIPTION = "XXX702_T001_L269-1";
    String SEND_ID_FOR_IB_SMS = "ADC739_S001_B005";
    String PHISING_SMS_BUTTON = "ADC739_S001_B008";
    String BLOCATION_ALL_PROFILES_BUTTON = "ADC739_S001_B001";
    String UNBLOCATION_ALL_PROFILES_BUTTON = "ADC739_S001_B019";
    String DETAIL_OF_CLIENT_BUTTON = "XXX702_T001_B016";
    String BLOCATION_OF_IB_CANAL_BUTTON = "ADC739_S001_B012";
    String STATE_OF_IB_CANAL = "ADC739_S001_L104";
    String CANAL_IN_ROW_DIV = "ADC739_S001_L077-1";
    String CANCEL_BLOCATION_OF_IB_CANAL_BUTTON = "ADC739_S001_P006-1";

    String BACK_BUTTON = "ADC739_S001_P002";
    String RC_IN_LIST_OF_PROFILES_WITH_PRIVILAGES_TO_IB_LABEL = "ADC739_S001_L010-1";
    String ADC_PRODUCTS_COMBOBOX = "ADC739_S001_C003";

    @Wait(DETAIL_EDISPONENT)
    @Click(value = DETAIL_EDISPONENT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC739_S001_IBSBPage clickDetailEdisponent();

    @Wait(SEND_LOGIN_PASSWORD_SMS)
    @Click(value = SEND_LOGIN_PASSWORD_SMS, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC739_S001_IBSBPage clickSendLoginPasswordSms();

    @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE)
    @CustomAction
    default ADC739_S001_IBSBPage checkIfStatusBarIsOverwritten(String textInStatusBar) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String fullText = endpoint.getText(STATUS_BAR);
        String textWithoutTime = fullText.replaceFirst("^\\d{2}:\\d{2}:\\d{2}", "");
        Assert.assertTrue(textWithoutTime.contains(textInStatusBar));
        return null;
    }

    @Wait(value = REQUIREMENT_BUTTON_XPATH, by = Lookup.XPATH, until = Until.CLICKABLE)
    @Click(value = REQUIREMENT_BUTTON_XPATH, by = Lookup.XPATH, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC739_S001_IBSBPage clickRequirement();

    @Wait(value = REFRESH_REQUIREMENT_BUTTON, until = Until.CLICKABLE)
    @Click(value = REFRESH_REQUIREMENT_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC739_S001_IBSBPage clickRefreshRequirement();

    @CheckElementContent(REQUIREMENT_DESCRIPTION)
    ADC739_S001_IBSBPage checkRequirementDescription(String description);

    @Wait(value = SEND_ID_FOR_IB_SMS, until = Until.CLICKABLE)
    @Click(SEND_ID_FOR_IB_SMS)
    @AcceptAlert(waitSecondsForAlert = 15, expectedAlertText = "Souhlasíte, aby Vám společnost koncernu MONETA Money Bank, a. s. jednorázově zaslala ID k Internet Bance na telefonní číslo mobilního klíče")
    ADC739_S001_IBSBPage clickSendIdForIbSms();

    @Wait(value = PHISING_SMS_BUTTON, until = Until.CLICKABLE)
    @Click(PHISING_SMS_BUTTON)
    @AcceptAlert(waitSecondsForAlert = 5, expectedAlertText = "Opravdu chcete klientovi odeslat SMS zprávu o blokaci Internet Banky z důvodu phishingu?")
    ADC739_S001_IBSBPage clickPhisingSms();

    @Wait(value = BLOCATION_ALL_PROFILES_BUTTON, until = Until.CLICKABLE)
    @Click(value = BLOCATION_ALL_PROFILES_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC739_S001_IBSBPage clickBlockationAllProfilesButton();

    @Wait(value = DETAIL_OF_CLIENT_BUTTON, until = Until.CLICKABLE)
    @Click(value = DETAIL_OF_CLIENT_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STS701_S002_ClientDetailPage clickDetailOfClientButton();

    @Wait(value = UNBLOCATION_ALL_PROFILES_BUTTON, until = Until.CLICKABLE)
    @Click(UNBLOCATION_ALL_PROFILES_BUTTON)
    @AcceptAlert(waitSecondsForAlert = 15, expectedAlertText = "ADC kanál blokován na žádost banky = podezření na podvod!        Ověřil si, že nemůže dojít k zneužití údajů klienta (IB a SB)?        Opravdu chcete kanál odblokovat?")
    ADC739_S001_IBSBPage clickUnblocationAllProfiles();

    @Wait(value = BLOCATION_OF_IB_CANAL_BUTTON, until = Until.CLICKABLE)
    @Click(value = BLOCATION_OF_IB_CANAL_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC739_S001_IBSBPage clickBloationOfIbCanal();

    @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE)
    @Wait(value = STATE_OF_IB_CANAL, until = Until.VISIBLE)
    @CheckElementContent(STATE_OF_IB_CANAL)
    ADC739_S001_IBSBPage checkStateOfIbCanal(String state);

    @Wait(value = CANAL_IN_ROW_DIV, until = Until.VISIBLE)
    @CheckElementContent(CANAL_IN_ROW_DIV)
    ADC739_S001_IBSBPage checkCanalInRow(String canal);

    @CustomAction
    default ADC739_S001_IBSBPage clickCancelBlocationOfIBCanal() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(20, Until.CLICKABLE, CANCEL_BLOCATION_OF_IB_CANAL_BUTTON);
        endpoint.click(() -> CANCEL_BLOCATION_OF_IB_CANAL_BUTTON);
        endpoint.acceptAlert(15);
        endpoint.waitForElementsToLoad(20, Lookup.CLASSNAME, Until.GONE, LOAD_IMG_DIV_CLASS);
        return null;
    }

    @CustomAction
    default ADC739_S001_IBSBPage scrollOnAllBlocationButton() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.scrollIntoView(BLOCATION_ALL_PROFILES_BUTTON);
        return null;
    }

    @CustomAction
    default ADC739_S001_IBSBPage scrollOnSmsPhishingButton() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.scrollIntoView(PHISING_SMS_BUTTON);
        return null;
    }

    @Click(value = BACK_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STS701_S002_ClientDetailPage clickBackButton();

    @Wait(value = RC_IN_LIST_OF_PROFILES_WITH_PRIVILAGES_TO_IB_LABEL, until = Until.VISIBLE)
    @CheckElementContent(RC_IN_LIST_OF_PROFILES_WITH_PRIVILAGES_TO_IB_LABEL)
    ADC739_S001_IBSBPage checkRcInListOfProfilesWithAccessToIb(String rc);

    @Select(value = ADC_PRODUCTS_COMBOBOX, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    STS701_S002_AdcProductsPanel selectAdcProduct(String product);
}