package com.atlassian.bitbucket.pull;

import javax.annotation.Nonnull;
import java.util.stream.Stream;

/**
 * Enumerates the different types of diffs a {@link PullRequest pull request} comment can be anchored to
 *
 * @since 4.7
 */
public enum PullRequestCommentAnchorDiffType {
    /**
     * The effective diff shows all the changes introduced by the pull request
     */
    EFFECTIVE(0),
    /**
     * The commit diff displays the changes introduced by one of the commits in the pull request
     */
    COMMIT(1);

    private final int id;

    PullRequestCommentAnchorDiffType(int id) {
        this.id = id;
    }

    @Nonnull
    public static PullRequestCommentAnchorDiffType fromId(int id) {
        return Stream.of(values())
                .filter(diff -> diff.getId() == id)
                .findFirst()
                .orElseThrow(() ->
                        new IllegalArgumentException("No PullRequestCommentAnchorDiffType is associated with ID [" + id + "]"));
    }

    public int getId() {
        return id;
    }
}
