import 'package:fpdart/fpdart.dart';

// Fehlerkategorien
enum AppErrorType {
  ValidationError,
  DatabaseError,
  NetworkError,
  UnknownError,
}

class AppError {
  final String message; // Benutzerfreundliche Fehlermeldung
  final AppErrorType type; // Typisierte Fehlerkategorie
  final Exception? exception; // Originale Exception (falls vorhanden)

  AppError({
    required this.message,
    this.type = AppErrorType.UnknownError,
    this.exception,
  });

  @override
  String toString() {
    return 'AppError(message: $message, type: $type, exception: $exception)';
  }

  /// Hilfsmethode zur einfachen Erstellung eines `Left`-Werts für `Either`
  static Either<AppError, T> left<T>(
    String message, {
    AppErrorType? type,
    Exception? exception,
  }) {
    return Either.left(AppError(
      message: message,
      type: type ?? AppErrorType.UnknownError,
      exception: exception,
    ));
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is AppError && other.message == message && other.type == type;
  }
}
