package com.atlassian.bitbucket.build;

import com.atlassian.event.api.AsynchronousPreferred;
import com.atlassian.bitbucket.event.ApplicationEvent;
import com.atlassian.bitbucket.event.annotation.TransactionAware;

import javax.annotation.Nonnull;

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Event that is raised when the build status for a commit is set.
 */
@AsynchronousPreferred
@TransactionAware
public class BuildStatusSetEvent extends ApplicationEvent {

    private final BuildStatus buildStatus;
    private final String commitId;

    public BuildStatusSetEvent(@Nonnull Object source, @Nonnull String commitId, @Nonnull BuildStatus buildStatus) {
        super(source);

        this.buildStatus = checkNotNull(buildStatus, "buildStatus");
        this.commitId = checkNotNull(commitId, "commitId");
    }

    /**
     * @return the {@link BuildStatus build status} that was set for the commit
     */
    @Nonnull
    public BuildStatus getBuildStatus() {
        return buildStatus;
    }

    /**
     * @return the commit ID for which the {@link BuildStatus build status} was set
     */
    @Nonnull
    public String getCommitId() {
        return commitId;
    }
}
