package com.atlassian.stash.internal.pull;

import com.atlassian.analytics.api.annotations.EventName;
import com.atlassian.event.api.AsynchronousPreferred;
import com.atlassian.bitbucket.commit.MinimalCommit;
import com.atlassian.bitbucket.event.pull.PullRequestMergedEvent;
import com.atlassian.bitbucket.pull.PullRequest;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;

@AsynchronousPreferred
@EventName("stash.pullrequest.merged")
public class AnalyticsPullRequestMergedEvent extends PullRequestMergedEvent {

    public AnalyticsPullRequestMergedEvent(@Nonnull Object source, @Nonnull PullRequest pullRequest) {
        super(source, pullRequest);
    }

    public AnalyticsPullRequestMergedEvent(@Nonnull Object source, @Nonnull PullRequest pullRequest,
                                           @Nullable MinimalCommit commit, @Nullable String message,
                                           @Nullable String strategyId, @Nonnull Map<String, Object> context) {
        super(source, pullRequest, commit, message, strategyId, context);
    }

    /**
     * @return the commit message length, which would be 0 if no commit message has been entered
     * @since 3.7
     */
    @SuppressWarnings("unused") //Used via Reflection by analytics
    public int getCustomMessageLength() {
        String message = getMessage();

        return message == null ? 0 : message.length();
    }
}
