class Lesson {
  final int bookingId;
  final String status;

  final String date; // YYYY-MM-DD
  final String startTime;
  final String endTime;
  final String? roomName;

  final String className;
  final String? level;

  final int availableEntries;
  final int availableRecoveries;

  final bool canModify;

  Lesson({
    required this.bookingId,
    required this.status,
    required this.date,
    required this.startTime,
    required this.endTime,
    required this.roomName,
    required this.className,
    required this.level,
    required this.availableEntries,
    required this.availableRecoveries,
    required this.canModify,
  });

  factory Lesson.fromJson(Map<String, dynamic> j) {
    final session = (j['session'] as Map<String, dynamic>? ?? {});
    final cls = (j['class'] as Map<String, dynamic>? ?? {});
    final wallet = (j['wallet'] as Map<String, dynamic>? ?? {});

    return Lesson(
      bookingId: (j['booking_id'] as num).toInt(),
      status: (j['status'] ?? '').toString(),
      date: (session['date'] ?? '').toString(),
      startTime: (session['start_time'] ?? '').toString(),
      endTime: (session['end_time'] ?? '').toString(),
      roomName: session['room_name']?.toString(),
      className: (cls['name'] ?? '').toString(),
      level: cls['level']?.toString(),
      availableEntries: (wallet['available_entries'] as num?)?.toInt() ?? 0,
      availableRecoveries:
          (wallet['available_recoveries'] as num?)?.toInt() ?? 0,
      canModify: (j['can_modify'] == true),
    );
  }
}
