// lib/features/admin/models/admin_incident.dart

class AdminIncidentModel {
  final String id;
  final int unitId;
  final String? routeId;
  // Mapea a `incidents.category` en la base de datos.
  final String type;
  final String? description;
  final String? driverName;
  final String status; // open | in_review | resolved
  final String? photoUrl;
  final DateTime createdAt;

  const AdminIncidentModel({
    required this.id,
    required this.unitId,
    this.routeId,
    required this.type,
    this.description,
    this.driverName,
    this.status = 'open',
    this.photoUrl,
    required this.createdAt,
  });

  factory AdminIncidentModel.fromJson(Map<String, dynamic> json) =>
      AdminIncidentModel(
        // El id en DB es BIGSERIAL; el backend lo serializa como string,
        // pero por defensa aceptamos number también.
        id: json['id'].toString(),
        unitId: (json['unit_id'] as num).toInt(),
        routeId: json['route_id'] as String?,
        type: (json['type'] as String?) ?? 'otro',
        description: json['description'] as String?,
        driverName: json['driver_name'] as String?,
        status: (json['status'] as String?) ?? 'open',
        photoUrl: json['photo_url'] as String?,
        createdAt: DateTime.parse(json['created_at'] as String),
      );

  String get typeLabel {
    switch (type) {
      case 'derrame':
        return 'Derrame';
      case 'dano_propiedad':
        return 'Daño a propiedad';
      case 'conducta':
        return 'Conducta';
      case 'no_recoleccion':
        return 'No recolección';
      default:
        return 'Otro';
    }
  }

  String get statusLabel {
    switch (status) {
      case 'in_review':
        return 'En revisión';
      case 'resolved':
        return 'Resuelta';
      default:
        return 'Abierta';
    }
  }
}
