package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.webdriver.bitbucket.element.AuiForm;

import java.lang.reflect.ParameterizedType;

public abstract class FormPage<S, C> extends BitbucketPage {

    @ElementBy(cssSelector = "form.aui")
    protected AuiForm form;

    public S clickSubmit(Object... args) {
        return form.submit((Class<S>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0], args);
    }

    public FormPage<S, C> clickSubmitExpectingErrors(Object... args) {
        return form.submit(getClass(), args);
    }

    public C clickCancel(Object... args) {
        return form.submit((Class<C>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1], args);
    }

}
