export class AppError extends Error {
  status: number;
  code: string;
  details?: unknown;

  constructor(status: number, message: string, code = 'error', details?: unknown) {
    super(message);
    this.status = status;
    this.code = code;
    this.details = details;
  }
}

export function badRequest(message: string, details?: unknown) {
  return new AppError(400, message, 'bad_request', details);
}

export function unauthorized(message = 'Authentication required') {
  return new AppError(401, message, 'unauthorized');
}

export function forbidden(message = 'Permission denied') {
  return new AppError(403, message, 'forbidden');
}

export function notFound(message = 'Not found') {
  return new AppError(404, message, 'not_found');
}

export function conflict(message: string) {
  return new AppError(409, message, 'conflict');
}
