package errcode

import (
	"google.golang.org/grpc/codes"
)

func HTTPStatusFromCode(code uint32) ErrCode {
	switch code {
	case uint32(codes.Canceled):
		return ErrCanceled
	case uint32(codes.Unknown):
		return ErrUnknown
	case uint32(codes.InvalidArgument):
		return ErrInvalidArgument
	case uint32(codes.DeadlineExceeded):
		return ErrDeadlineExceeded
	case uint32(codes.NotFound):
		return ErrNotFound
	case uint32(codes.AlreadyExists):
		return ErrAlreadyExists
	case uint32(codes.PermissionDenied):
		return ErrPermissionDenied
	case uint32(codes.Unauthenticated):
		return ErrUnauthenticated
	case uint32(codes.ResourceExhausted):
		return ErrResourceExhausted
	case uint32(codes.FailedPrecondition):
		// Note, this deliberately doesn't translate to the similarly named '412 Precondition Failed' HTTP response status.
		return ErrFailedPrecondition
	case uint32(codes.Aborted):
		return ErrAborted
	case uint32(codes.OutOfRange):
		return ErrOutOfRange
	case uint32(codes.Unimplemented):
		return ErrUnimplemented
	case uint32(codes.Internal):
		return ErrInternal
	case uint32(codes.Unavailable):
		return ErrUnavailable
	case uint32(codes.DataLoss):
		return ErrDataLoss
	default:
		return ErrInternal
	}
}
