package com.atlassian.bitbucket.mesh.git;

import com.atlassian.bitbucket.mesh.git.exception.UnsupportedArgumentException;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcUploadType;

import javax.annotation.Nonnull;

import static com.atlassian.bitbucket.mesh.rpc.v1.RpcUnsupportedArgument.Reason.UNSUPPORTED_UPLOAD_TYPE;
import static com.atlassian.bitbucket.mesh.rpc.v1.RpcUploadType.*;

/**
 * The type of file / files that are {@link UploadManager#uploadFile(UploadFileParameters) offered for upload}.
 */
public enum UploadType {

    GIT_DARK_REFS(UPLOAD_TYPE_GIT_DARK_REFS),
    GIT_LFS(UPLOAD_TYPE_GIT_LFS),
    GIT_LOG(UPLOAD_TYPE_GIT_LOG),
    GIT_OBJECTS(UPLOAD_TYPE_GIT_OBJECTS),
    GIT_REFS(UPLOAD_TYPE_GIT_REFS),
    GIT_ROOT(UPLOAD_TYPE_GIT_ROOT);

    private final RpcUploadType rpc;

    UploadType(RpcUploadType rpcType) {
        rpc = rpcType;
    }

    @Nonnull
    public static UploadType fromRpc(@Nonnull RpcUploadType rpc) {
        for (UploadType value : values()) {
            if (rpc == value.rpc) {
                return value;
            }
        }
        throw new UnsupportedArgumentException(UNSUPPORTED_UPLOAD_TYPE, rpc);
    }

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