import { HttpStatus } from '@nestjs/common';
import { MESSAGES } from './messages';

// Base error function
export const error = (message: string, statusCode: HttpStatus) => ({
  success: false,
  statusCode,
  message,
  error: HttpStatus[statusCode],
});

// Common error cases
export const authError = (msg = MESSAGES.AUTH.UNAUTHORIZED) =>
  error(msg, HttpStatus.UNAUTHORIZED);

export const notFound = (msg = 'Resource not found') =>
  error(msg, HttpStatus.NOT_FOUND);

// This makes controller code more concise:
// return next(notFound(MESSAGES.CHAT.NOT_FOUND));
