import 'package:intl/intl.dart';

class LearningHistory {
  final int? score;
  final String currentLevel;
  final String? nextLevel;
  final DateTime? studentFinish;
  final String topicName;
  final String sectionName;
  final bool isPass;

  LearningHistory({
    required this.score,
    required this.currentLevel,
    required this.nextLevel,
    required this.studentFinish,
    required this.topicName,
    required this.sectionName,
    required this.isPass,
  });

  factory LearningHistory.fromJson(Map<String, dynamic> json) {
    return LearningHistory(
      score: json['SCORE'] ?? 0,
      currentLevel: json['CURRENT_LEVEL'] ?? 'Unknown',
      nextLevel: json['NEXT_LEVEL'],
      studentFinish: json['STUDENT_FINISH'] != null
          ? DateTime.parse(json['STUDENT_FINISH'])
          : null,
      topicName: json['TOPIC_NAME'] ?? 'Unknown Topic',
      sectionName: json['SECTION_NAME'] ?? 'Unknown Section',
      isPass: json['IS_PASS'] == 1,
    );
  }

  String get formattedDate {
    return studentFinish != null
        ? DateFormat('yyyy-MM-dd HH:mm').format(studentFinish!)
        : 'N/A';
  }
}
