class EventModel {
  final String id;
  final String title;
  final String? description;
  final DateTime startDate;
  final DateTime? endDate;
  final EventType type;
  final EventStatus status;
  final String? childId;
  final String? assistantId;
  final String? createdBy;

  EventModel({
    required this.id,
    required this.title,
    this.description,
    required this.startDate,
    this.endDate,
    required this.type,
    required this.status,
    this.childId,
    this.assistantId,
    this.createdBy,
  });

  factory EventModel.fromJson(Map<String, dynamic> json) {
    return EventModel(
      id: json['id'],
      title: json['title'],
      description: json['description'],
      startDate: DateTime.parse(json['startDate']),
      endDate: json['endDate'] != null ? DateTime.parse(json['endDate']) : null,
      type: EventType.values.byName(json['type']),
      status: EventStatus.values.byName(json['status']),
      childId: json['childId'],
      assistantId: json['assistantId'],
      createdBy: json['createdBy'],
    );
  }

  bool get isMultiDay => endDate != null && !isSameDay(startDate, endDate!);
  bool get isPending => status == EventStatus.pending;
  bool get needsConfirmation => isPending && createdBy != 'current_user';

  static bool isSameDay(DateTime date1, DateTime date2) {
    return date1.year == date2.year && 
           date1.month == date2.month && 
           date1.day == date2.day;
  }
}

enum EventType {
  parentVacation,      // Vacances parents
  childAbsence,        // Absence enfant
  rpeActivity,         // Activité RPE
  assistantVacation,   // Congés assistante maternelle
  sickLeave,           // Arrêt maladie
  personalNote,        // Note personnelle
}

enum EventStatus {
  confirmed,
  pending,
  refused,
  cancelled,
}