/// Exception de base pour l'application
abstract class AppException implements Exception {
  final String message;
  final String? code;

  const AppException(this.message, [this.code]);

  @override
  String toString() => 'AppException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception serveur
class ServerException extends AppException {
  const ServerException(super.message, [super.code]);

  @override
  String toString() => 'ServerException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception de cache
class CacheException extends AppException {
  const CacheException(super.message, [super.code]);

  @override
  String toString() => 'CacheException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception de réseau
class NetworkException extends AppException {
  const NetworkException(super.message, [super.code]);

  @override
  String toString() => 'NetworkException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception d'authentification
class AuthException extends AppException {
  const AuthException(super.message, [super.code]);

  @override
  String toString() => 'AuthException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception de validation
class ValidationException extends AppException {
  const ValidationException(super.message, [super.code]);

  @override
  String toString() => 'ValidationException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception non autorisé (401)
class UnauthorizedException extends AppException {
  const UnauthorizedException([super.message = 'Non autorisé', super.code]);

  @override
  String toString() => 'UnauthorizedException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception non trouvé (404)
class NotFoundException extends AppException {
  const NotFoundException([super.message = 'Ressource non trouvée', super.code]);

  @override
  String toString() => 'NotFoundException: $message${code != null ? ' (Code: $code)' : ''}';
}

/// Exception interdit (403)
class ForbiddenException extends AppException {
  const ForbiddenException([super.message = 'Accès interdit', super.code]);

  @override
  String toString() => 'ForbiddenException: $message${code != null ? ' (Code: $code)' : ''}';
}
