/// 每日在线时长统计模型
class KRDailyOnlineStat {
  final int day;
  final String dayName;
  final double hours;

  KRDailyOnlineStat({
    required this.day,
    required this.dayName,
    required this.hours,
  });

  factory KRDailyOnlineStat.fromJson(Map<String, dynamic> json) {
    return KRDailyOnlineStat(
      day: json['day'] ?? 0,
      dayName: json['day_name'] ?? '',
      hours: (json['hours'] ?? 0.0).toDouble(),
    );
  }
}

/// 在线时长记录模型
class KROnlineDurationRecord {
  final int currentContinuousDays;
  final int historyContinuousDays;
  final int longestSingleConnection;

  KROnlineDurationRecord({
    required this.currentContinuousDays,
    required this.historyContinuousDays,
    required this.longestSingleConnection,
  });

  factory KROnlineDurationRecord.fromJson(Map<String, dynamic> json) {
    return KROnlineDurationRecord(
      currentContinuousDays: json['current_continuous_days'] ?? 0,
      historyContinuousDays: json['history_continuous_days'] ?? 0,
      longestSingleConnection: json['longest_single_connection'] ?? 0,
    );
  }
}

/// 用户在线时长统计响应模型
class KRUserOnlineDurationResponse {
  final List<KRDailyOnlineStat> weeklyStats;
  final KROnlineDurationRecord connectionRecords;

  KRUserOnlineDurationResponse({
    required this.weeklyStats,
    required this.connectionRecords,
  });

  factory KRUserOnlineDurationResponse.fromJson(Map<String, dynamic> json) {
    return KRUserOnlineDurationResponse(
      weeklyStats: (json['weekly_stats'] as List?)
          ?.map((e) => KRDailyOnlineStat.fromJson(e as Map<String, dynamic>))
          .toList() ?? [],
      connectionRecords: KROnlineDurationRecord.fromJson(
        json['connection_records'] as Map<String, dynamic>? ?? {},
      ),
    );
  }
}