import { HttpStatus } from '@nestjs/common';
import { ErrorResponse } from '../config';

/**
 * Format a single error message into the standardized error format
 * @param path - Field path (e.g., 'email', 'user.profile.name')
 * @param message - Error message
 * @param status - HTTP status code (default: 400)
 */
export const createFieldError = (
  path: string,
  message: string,
  status: HttpStatus = HttpStatus.BAD_REQUEST,
) => {
  return new ErrorResponse([{ path, message }], status);
};

/**
 * Format multiple error messages into the standardized error format
 * @param errors - Array of { path, message } objects
 * @param status - HTTP status code (default: 400)
 */
export const createFieldErrors = (
  errors: Array<{ path: string; message: string }>,
  status: HttpStatus = HttpStatus.BAD_REQUEST,
) => {
  return new ErrorResponse(errors, status);
};

/**
 * Convert a simple string error message to field error format
 * Useful for business logic errors that need standard formatting
 * @param message - Error message
 * @param fieldPath - Field path where error occurred (default: 'general')
 * @param status - HTTP status code (default: 400)
 */
export const createGeneralError = (
  message: string,
  fieldPath: string = 'general',
  status: HttpStatus = HttpStatus.BAD_REQUEST,
) => {
  return new ErrorResponse([{ path: fieldPath, message }], status);
};
