package com.atlassian.stash.internal.web.conditions;

import com.atlassian.plugin.PluginParseException;
import com.atlassian.plugin.web.Condition;
import com.atlassian.stash.internal.watcher.InternalWatcherService;
import com.atlassian.bitbucket.pull.PullRequest;

import java.util.Map;

/**
 * A condition which checks if the current user is watching the current pull request
 *
 * @since 1.3
 */
public class HasPullRequestWatchCondition implements Condition {

    private static final String PULL_REQUEST = "pullRequest";

    private final InternalWatcherService watcherService;

    public HasPullRequestWatchCondition(InternalWatcherService watcherService) {
        this.watcherService = watcherService;
    }

    @Override
    public void init(Map<String, String> params) throws PluginParseException {
    }

    @Override
    public boolean shouldDisplay(Map<String, Object> context) {
        return watcherService.isCurrentUserWatching((PullRequest) context.get(PULL_REQUEST));
    }
}
