class ContractModel {
  final String id;
  final String childId;
  final String assistantId;
  final ContractStatus status;
  final DateTime startDate;
  final DateTime? endDate;
  final double hourlyRate;
  final Map<String, dynamic>? terms;
  final DateTime createdAt;
  final DateTime? signedAt;

  ContractModel({
    required this.id,
    required this.childId,
    required this.assistantId,
    required this.status,
    required this.startDate,
    this.endDate,
    required this.hourlyRate,
    this.terms,
    required this.createdAt,
    this.signedAt,
  });

  factory ContractModel.fromJson(Map<String, dynamic> json) {
    return ContractModel(
      id: json['id'],
      childId: json['childId'],
      assistantId: json['assistantId'],
      status: ContractStatus.values.byName(json['status']),
      startDate: DateTime.parse(json['startDate']),
      endDate: json['endDate'] != null ? DateTime.parse(json['endDate']) : null,
      hourlyRate: json['hourlyRate'].toDouble(),
      terms: json['terms'],
      createdAt: DateTime.parse(json['createdAt']),
      signedAt: json['signedAt'] != null ? DateTime.parse(json['signedAt']) : null,
    );
  }

  bool get isActive => status == ContractStatus.active;
  bool get needsSignature => status == ContractStatus.draft;
  String get statusLabel {
    switch (status) {
      case ContractStatus.draft:
        return 'Brouillon';
      case ContractStatus.pending:
        return 'En attente de validation';
      case ContractStatus.active:
        return 'En cours';
      case ContractStatus.ended:
        return 'Terminé';
      case ContractStatus.cancelled:
        return 'Annulé';
    }
  }
}

enum ContractStatus {
  draft,
  pending,
  active,
  ended,
  cancelled,
}