import '../../domain/entities/error_entity.dart';

class ErrorModel extends ErrorEntity {
  const ErrorModel({super.detail});

  Map<String, dynamic> toJson() {
    return {"detail": detail};
  }

  factory ErrorModel.fromJson(Map<String, dynamic> data) {
    if (data.containsKey("detail")) {
      if (data['detail'] is List) {
        return ErrorModel(detail: data['detail'][0]["msg"]);
      } else {
        return ErrorModel(detail: data['detail']);
      }
    }
    return ErrorModel(detail: data['error']);
  }
}
