package com.atlassian.stash.internal.pull;

import com.atlassian.stash.internal.AbstractService;
import com.atlassian.stash.internal.annotation.RewriteExceptions;
import com.atlassian.bitbucket.pull.PullRequestSupplier;
import org.springframework.security.access.prepost.PostAuthorize;

/**
 * @since 3.6
 */
@RewriteExceptions
public class DefaultPullRequestSupplier extends AbstractService implements PullRequestSupplier {

    protected final PullRequestDao pullRequestDao;

    public DefaultPullRequestSupplier(PullRequestDao pullRequestDao) {
        this.pullRequestDao = pullRequestDao;
    }

    @Override
    @PostAuthorize("hasRepositoryPermission(returnObject?.scopeRepository, 'REPO_READ')")
    public InternalPullRequest getById(int repositoryId, long pullRequestId) {
        return pullRequestDao.findByRepositoryScopedId(repositoryId, pullRequestId);
    }
}
