class EventOption {
  final String id;
  final String code; // Nouveau champ code
  final String name;
  final String details;
  final double valMin;
  final double valMax;
  final List<String> eventTypes; // Changé de List<DocumentReference> à List<String>
  final bool isQuantitative; // Indique si l'option peut avoir une quantité

  EventOption({
    required this.id,
    required this.code,
    required this.name,
    required this.details,
    required this.valMin,
    required this.valMax,
    required this.eventTypes,
    this.isQuantitative = false,
  });

  factory EventOption.fromMap(Map<String, dynamic> map, String id) {
    return EventOption(
      id: id,
      code: map['code'] ?? id, // Utilise le code ou l'ID en fallback
      name: map['name'] ?? '',
      details: map['details'] ?? '',
      valMin: (map['valMin'] ?? 0.0).toDouble(),
      valMax: (map['valMax'] ?? 0.0).toDouble(),
      eventTypes: (map['eventTypes'] as List<dynamic>? ?? [])
          .map((e) => e.toString()) // Convertit en String (supporte IDs et références)
          .toList(),
      isQuantitative: map['isQuantitative'] ?? false,
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'code': code,
      'name': name,
      'details': details,
      'valMin': valMin,
      'valMax': valMax,
      'eventTypes': eventTypes,
      'isQuantitative': isQuantitative,
    };
  }
}
