/**
 * Base class for all HTTP-related errors.
 * Extends the built-in Error with a status code and message
 * so that they can be handled in a consistent way.
 */
export class HttpError extends Error {
  public statusCode: number;

  constructor(message: string, statusCode: number) {
    super(message);
    this.statusCode = statusCode;

    // Restore prototype chain (important when targeting ES5/ES2015+)
    Object.setPrototypeOf(this, new.target.prototype);
  }
}

export class ValidationError extends HttpError {
  constructor(message: string) {
    super(message, 400); // Bad Request
  }
}

export class UnauthorizedError extends HttpError {
  constructor(message: string = "Unauthorized") {
    super(message, 401);
  }
}

export class NotFoundError extends HttpError {
  constructor(message: string = "Resource not found") {
    super(message, 404);
  }
}

export class ConflictError extends HttpError {
  constructor(message: string = "Conflict") {
    super(message, 409);
  }
}

export class InternalServerError extends HttpError {
  constructor(message: string = "Internal Server Error") {
    super(message, 500);
  }
}
