package com.atlassian.bitbucket.mesh.git.pull;

import com.atlassian.bitbucket.mesh.rpc.v1.RpcPullRequestState;

import javax.annotation.Nonnull;

import static com.atlassian.bitbucket.mesh.rpc.v1.RpcPullRequestState.*;
import static java.util.Objects.requireNonNull;

public enum PullRequestState {

    DECLINED(PR_STATE_DECLINED),
    MERGED(PR_STATE_MERGED),
    OPEN(PR_STATE_OPEN);

    final RpcPullRequestState rpc;

    PullRequestState(RpcPullRequestState rpc) {
        this.rpc = rpc;
    }

    @Nonnull
    public static PullRequestState fromRpc(@Nonnull RpcPullRequestState rpc) {
        switch (requireNonNull(rpc, "rpc")) {
            case PR_STATE_DECLINED:
                return DECLINED;
            case PR_STATE_MERGED:
                return MERGED;
            default:
                return OPEN;
        }
    }

    @Nonnull
    public RpcPullRequestState toRpc() {
        return rpc;
    }
}
