import 'package:sigap/src/features/panic-button/data/models/models/incident_logs_model.dart';

class EvidenceModel {
  final String id;
  final String incidentId;
  final String type;
  final String url;
  final String? description;
  final String? caption;
  final Map<String, dynamic>? metadata;
  final DateTime? uploadedAt;
  final IncidentLogModel? incident;

  EvidenceModel({
    required this.id,
    required this.incidentId,
    required this.type,
    required this.url,
    this.description,
    this.caption,
    this.metadata,
    this.uploadedAt,
    this.incident,
  });

  // Create an EvidenceModel instance from a JSON object
  factory EvidenceModel.fromJson(Map<String, dynamic> json) {
    return EvidenceModel(
      id: json['id'] as String,
      incidentId: json['incident_id'] as String,
      type: json['type'] as String,
      url: json['url'] as String,
      description: json['description'] as String?,
      caption: json['caption'] as String?,
      metadata: json['metadata'] as Map<String, dynamic>?,
      uploadedAt:
          json['uploaded_at'] != null
              ? DateTime.parse(json['uploaded_at'] as String)
              : null,
      incident:
          json['incident'] != null
              ? IncidentLogModel.fromJson(
                json['incident'] as Map<String, dynamic>,
              )
              : null,
    );
  }

  // Convert an EvidenceModel instance to a JSON object
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'incident_id': incidentId,
      'type': type,
      'url': url,
      'description': description,
      'caption': caption,
      'metadata': metadata,
      'uploaded_at': uploadedAt?.toIso8601String(),
    };
  }

  // Create a copy of the EvidenceModel with updated fields
  EvidenceModel copyWith({
    String? id,
    String? incidentId,
    String? type,
    String? url,
    String? description,
    String? caption,
    Map<String, dynamic>? metadata,
    DateTime? uploadedAt,
    IncidentLogModel? incident,
  }) {
    return EvidenceModel(
      id: id ?? this.id,
      incidentId: incidentId ?? this.incidentId,
      type: type ?? this.type,
      url: url ?? this.url,
      description: description ?? this.description,
      caption: caption ?? this.caption,
      metadata: metadata ?? this.metadata,
      uploadedAt: uploadedAt ?? this.uploadedAt,
      incident: incident ?? this.incident,
    );
  }

  @override
  String toString() {
    return 'EvidenceModel(id: $id, type: $type)';
  }
}
