package com.atlassian.bitbucket.mesh.git;

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

import javax.annotation.Nonnull;

import static com.atlassian.bitbucket.mesh.rpc.v1.RpcTagType.TAG_ANNOTATED;
import static com.atlassian.bitbucket.mesh.rpc.v1.RpcTagType.TAG_LIGHTWEIGHT;

public enum GitTagType {

    /**
     * A tag annotated with details about when it was created and by whom.
     * <p>
     * Note: If a type isn't explicitly specified, this is the default. This differs from {@code git tag},
     * which will create {@link #LIGHTWEIGHT lightweight} tags by default.
     */
    ANNOTATED(TAG_ANNOTATED),
    /**
     * A simple tag directly referencing a commit. Lightweight tags do not track when, or by whom, they were created.
     */
    LIGHTWEIGHT(TAG_LIGHTWEIGHT);

    private final RpcTagType rpc;

    GitTagType(@Nonnull RpcTagType rpc) {
        this.rpc = rpc;
    }

    @Nonnull
    public static GitTagType fromRpc(@Nonnull RpcTagType rpc) {
        for (GitTagType type : values()) {
            if (type.rpc == rpc) {
                return type;
            }
        }

        return ANNOTATED; // tags are annotated by default
    }

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