package cz.moneta.test.dsl.ib.settings.ib.limit;

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.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.TypeInto;
import cz.moneta.test.harness.support.web.Wait;
import org.junit.Assert;

import static cz.moneta.test.dsl.ib.settings.ib.limit.IbConfirmLimitPage.CHANGE_LIMIT_HEADER;
import static cz.moneta.test.dsl.ib.settings.ib.limit.IbConfirmLimitPage.LIMIT_REDUCTION_LABEL;

@Wait({CHANGE_LIMIT_HEADER, LIMIT_REDUCTION_LABEL})
public interface IbConfirmLimitPage extends IbPageFlow<IbConfirmLimitPage>, StoreAccessor {
    String CHANGE_LIMIT_HEADER = "//table[@id = 'titleLabelTable']";
    String LIMIT_REDUCTION_LABEL = "//td[contains(text(), 'Požadavek')]";
    String LIMIT_VALUE = "//td[contains(text(), 'Denní limit')]//following-sibling::td";
    String MOBILE_KEY = "SMSCode";
    String SIGN_BTN = "sendBtn";

    @CustomAction
    default IbConfirmLimitPage compareLimit(int previousLimit) {
        IbEndpoint ibEndpoint = getEndpoint(IbEndpoint.class);
        String limitValue = ibEndpoint.getText(LIMIT_VALUE);
        Assert.assertEquals("Previous limit is not equal to limit value", String.valueOf(previousLimit), limitValue.replaceAll(" ", ""));
        return null;
    }

    @TypeInto(value = MOBILE_KEY, by = Lookup.ID)
    @Click(value = SIGN_BTN, by = Lookup.ID)
    IbChangeLimitFinalPage setMobileKeyAndSign(String smsCode);
}
