class ChildModel {
  final String id;
  final String firstName;
  final String? lastName;
  final String? photoUrl;
  final DateTime birthDate;
  final ChildStatus status;
  final String? assistantId;

  ChildModel({
    required this.id,
    required this.firstName,
    this.lastName,
    this.photoUrl,
    required this.birthDate,
    required this.status,
    this.assistantId,
  });

  factory ChildModel.fromJson(Map<String, dynamic> json) {
    return ChildModel(
      id: json['id'],
      firstName: json['firstName'],
      lastName: json['lastName'],
      photoUrl: json['photoUrl'],
      birthDate: DateTime.parse(json['birthDate']),
      status: ChildStatus.values.byName(json['status']),
      assistantId: json['assistantId'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'firstName': firstName,
      'lastName': lastName,
      'photoUrl': photoUrl,
      'birthDate': birthDate.toIso8601String(),
      'status': status.name,
      'assistantId': assistantId,
    };
  }

  String get fullName => lastName != null ? '$firstName $lastName' : firstName;
  
  int get ageInMonths {
    final now = DateTime.now();
    return (now.year - birthDate.year) * 12 + (now.month - birthDate.month);
  }
}

enum ChildStatus {
  withAssistant,    // En garde chez l'assistante
  available,        // Disponible
  onHoliday,        // En vacances
  sick,             // Malade
  searching,        // Recherche d'assistante
}