class ApiError {
  const ApiError({
    required this.error,
    required this.code,
    required this.details,
  });

  final String error;
  final String code;
  final Map<String, dynamic> details;

  factory ApiError.fromJson(Map<String, dynamic> json) {
    return ApiError(
      error: json['error'] as String? ?? '',
      code: json['code'] as String? ?? '',
      details: json['details'] as Map<String, dynamic>? ?? {},
    );
  }

  Map<String, dynamic> toJson() {
    return {'error': error, 'code': code, 'details': details};
  }
}

class ApiException implements Exception {
  const ApiException({required this.statusCode, required this.apiError});

  final int statusCode;
  final ApiError apiError;

  String get code => apiError.code;
  String get message => apiError.error;

  @override
  String toString() {
    return 'ApiException($statusCode, $code, $message)';
  }
}
