export class AppError extends Error {
  public readonly statusCode: number;
  public readonly error: string;
  public readonly details?: Record<string, string[]>;

  public constructor(
    statusCode: number,
    error: string,
    message: string,
    details?: Record<string, string[]>,
  ) {
    super(message);
    this.statusCode = statusCode;
    this.error = error;
    this.details = details;
    Object.setPrototypeOf(this, new.target.prototype);
    this.name = new.target.name;
  }
}

export class NotFoundError extends AppError {
  public constructor(message = 'Resource not found') {
    super(404, 'Not Found', message);
  }
}

export class UnauthorizedError extends AppError {
  public constructor(message = 'Unauthorized') {
    super(401, 'Unauthorized', message);
  }
}

export class ForbiddenError extends AppError {
  public constructor(message = 'Forbidden') {
    super(403, 'Forbidden', message);
  }
}

export class ConflictError extends AppError {
  public constructor(message = 'Conflict') {
    super(409, 'Conflict', message);
  }
}

export class BadRequestError extends AppError {
  public constructor(message = 'Bad Request', details?: Record<string, string[]>) {
    super(400, 'Bad Request', message, details);
  }
}
