class ApiException implements Exception {
  final String message;
  final int? statusCode;
  final List<FieldError> fieldErrors;

  const ApiException({
    required this.message,
    this.statusCode,
    this.fieldErrors = const [],
  });

  @override
  String toString() => 'ApiException: $message (status: $statusCode)';
}

class FieldError {
  final String field;
  final List<String> errors;

  const FieldError({required this.field, required this.errors});

  factory FieldError.fromJson(Map<String, dynamic> json) {
    return FieldError(
      field: json['field'] as String? ?? '',
      errors: (json['errors'] as List<dynamic>?)
              ?.map((e) => e.toString())
              .toList() ??
          [],
    );
  }
}
