/**
 * Typed Error Classes for DashCaddy API
 * Provides structured errors that the global error handler catches automatically.
 */

class AppError extends Error {
  constructor(message, statusCode = 500, code = 'INTERNAL_ERROR') {
    super(message);
    this.name = this.constructor.name;
    this.statusCode = statusCode;
    this.code = code;
  }
}

class DockerError extends AppError {
  constructor(message, details = {}) {
    super(message, 500, 'DOCKER_ERROR');
    this.details = details;
  }
}

class CaddyError extends AppError {
  constructor(message, details = {}) {
    super(message, 502, 'CADDY_ERROR');
    this.details = details;
  }
}

class DNSError extends AppError {
  constructor(message, details = {}) {
    super(message, 502, 'DNS_ERROR');
    this.details = details;
  }
}

class AuthenticationError extends AppError {
  constructor(message = 'Authentication required') {
    super(message, 401, 'AUTH_REQUIRED');
  }
}

class NotFoundError extends AppError {
  constructor(resource = 'Resource') {
    super(`${resource} not found`, 404, 'NOT_FOUND');
  }
}

module.exports = { AppError, DockerError, CaddyError, DNSError, AuthenticationError, NotFoundError };
