package com.atlassian.stash.internal.pull;

import com.atlassian.bitbucket.pull.PullRequestMergeVeto;
import com.atlassian.bitbucket.pull.PullRequestMergeability;
import com.atlassian.bitbucket.scm.pull.MergeRequest;
import com.atlassian.bitbucket.scm.pull.MergeRequestCheck;
import com.atlassian.bitbucket.scm.pull.MergeRequestCheckService;

import javax.annotation.Nonnull;

/**
 * @since 3.7
 */
public interface InternalMergeRequestCheckService extends MergeRequestCheckService {

    /**
     * Applies all registered and enabled {@link MergeRequestCheck}s to determine if a pull request merge should
     * proceed. If any check {@link MergeRequest#veto(String, String) vetoes} the {@link MergeRequest} then the
     * merge should not be performed. A {@link PullRequestMergeVeto PullRequestMergeVeto} will be returned for
     * each failed check. If no checks veto the merge it should be allowed to proceed.
     *
     * @param mergeRequest the merge request, providing additional details about the merge
     * @return the computed mergeability for the pull request, which considers both {@link MergeRequestCheck}s
     *         and whether the SCM indicates the pull request can be merged
     */
    @Nonnull
    PullRequestMergeability checkMergeability(@Nonnull InternalMergeRequest mergeRequest);
}
