class SymptomModel {
  final String id;
  final String name;
  final String nameAr;
  final String? organId;

  const SymptomModel({
    required this.id,
    required this.name,
    this.nameAr = '',
    this.organId,
  });

  SymptomModel copyWith({
    String? id,
    String? name,
    String? nameAr,
    String? organId,
  }) {
    return SymptomModel(
      id: id ?? this.id,
      name: name ?? this.name,
      nameAr: nameAr ?? this.nameAr,
      organId: organId ?? this.organId,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'nameAr': nameAr,
      'organId': organId,
    };
  }

  factory SymptomModel.fromJson(Map<String, dynamic> json) {
    return SymptomModel(
      id: json['id'] ?? '',
      name: json['name'] ?? '',
      nameAr: json['nameAr'] ?? '',
      organId: json['organId'],
    );
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is SymptomModel && other.id == id;
  }

  @override
  int get hashCode => id.hashCode;

  @override
  String toString() {
    return 'SymptomModel(id: $id, name: $name, nameAr: $nameAr, organId: $organId)';
  }
}

/// Class to group symptoms by organ
class OrganSymptomsGroup {
  final String organId;
  final String organName;
  final List<SymptomModel> symptoms;
  final Set<String> selectedSymptomIds;

  OrganSymptomsGroup({
    required this.organId,
    required this.organName,
    required this.symptoms,
    Set<String>? selectedSymptomIds,
  }) : selectedSymptomIds = selectedSymptomIds ?? {};

  /// Get count of selected symptoms
  int get selectedCount => selectedSymptomIds.length;

  /// Check if any symptoms are selected
  bool get hasSelectedSymptoms => selectedSymptomIds.isNotEmpty;

  /// Get list of selected symptoms
  List<SymptomModel> get selectedSymptoms {
    return symptoms.where((symptom) => selectedSymptomIds.contains(symptom.id)).toList();
  }

  OrganSymptomsGroup copyWith({
    String? organId,
    String? organName,
    List<SymptomModel>? symptoms,
    Set<String>? selectedSymptomIds,
  }) {
    return OrganSymptomsGroup(
      organId: organId ?? this.organId,
      organName: organName ?? this.organName,
      symptoms: symptoms ?? this.symptoms,
      selectedSymptomIds: selectedSymptomIds ?? this.selectedSymptomIds,
    );
  }

  @override
  String toString() {
    return 'OrganSymptomsGroup(organId: $organId, organName: $organName, symptomsCount: ${symptoms.length}, selectedCount: $selectedCount)';
  }
}

