export class AppError extends Error {
  readonly statusCode: number
  readonly error: string
  readonly data?: Record<string, unknown>

  constructor(message: string, statusCode: number, error: string, data?: Record<string, unknown>) {
    super(message)
    this.statusCode = statusCode
    this.error = error
    this.data = data
    this.name = this.constructor.name
  }
}

export class ValidationError extends AppError {
  constructor(message = 'Validation error') {
    super(message, 400, 'validation_error')
  }
}

export class NotFoundError extends AppError {
  constructor(message = 'Resource not found') {
    super(message, 404, 'not_found')
  }
}

export class ConflictError extends AppError {
  constructor(message = 'A resource with this value already exists') {
    super(message, 409, 'conflict')
  }
}

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

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