/**
 * Mutation Error Type
 * 
 * Errors that can be handled by the client after a mutation.
 * These are mapped from DomainErrors by Mutations.
 */

export type MutationError =
  | 'userNotFound'       // User doesn't exist
  | 'noPermission'       // Insufficient permissions
  | 'invalidData'        // Validation failed
  | 'updateFailed'       // Update operation failed
  | 'deleteFailed'       // Delete operation failed
  | 'createFailed'       // Create operation failed
  | 'networkError'       // Network/communication error
  | 'serverError'        // Generic server error
  | 'notImplemented'     // Feature not implemented
  | 'unknown';           // Unknown error

// Helper to map DomainError to MutationError
export function mapToMutationError(domainError: any): MutationError {
  const errorType = domainError?.type || domainError?.name || 'unknown';
  
  switch (errorType) {
    case 'notFound':
    case 'NotFoundError':
    case 'userNotFound':
      return 'userNotFound';
    case 'unauthorized':
    case 'UnauthorizedError':
    case 'ForbiddenError':
      return 'noPermission';
    case 'validationError':
    case 'ValidationError':
      return 'invalidData';
    case 'serverError':
    case 'ServerError':
    case 'HttpServerError':
      return 'serverError';
    case 'networkError':
    case 'NetworkError':
      return 'networkError';
    case 'notImplemented':
    case 'NotImplementedError':
      return 'notImplemented';
    default:
      return 'unknown';
  }
}
