class RecordingItem {
  const RecordingItem({
    required this.id,
    required this.sessionId,
    required this.title,
    required this.opponentName,
    required this.teamName,
    this.status = 'ready',
    this.statusLabel = 'Disponibile',
    this.privacyStatus = 'unlisted',
    this.endedAt,
    this.recordedAt,
    this.replayUrl,
    this.playbackUrl,
    this.thumbnailUrl,
    this.durationLabel,
    this.viewCount = 0,
    this.viewsLabel,
    this.downloadEnabled = false,
    this.youtubeWatchUrl,
    this.expiresAt,
  });

  final String id;
  final String sessionId;
  final String title;
  final String opponentName;
  final String teamName;
  final String status;
  final String statusLabel;
  final String privacyStatus;
  final DateTime? endedAt;
  final DateTime? recordedAt;
  final String? replayUrl;
  final String? playbackUrl;
  final String? thumbnailUrl;
  final String? durationLabel;
  final int viewCount;
  final String? viewsLabel;
  final bool downloadEnabled;
  final String? youtubeWatchUrl;
  final DateTime? expiresAt;

  bool get isReady => status == 'ready';
  bool get isProcessing => status == 'processing';

  factory RecordingItem.fromJson(Map<String, dynamic> json) {
    return RecordingItem(
      id: json['id'] as String,
      sessionId: json['session_id'] as String,
      title: json['title'] as String? ?? '${json['team_name']} vs ${json['opponent_name']}',
      opponentName: json['opponent_name'] as String,
      teamName: json['team_name'] as String,
      status: json['status'] as String? ?? 'ready',
      statusLabel: json['status_label'] as String? ?? 'Disponibile',
      privacyStatus: json['privacy_status'] as String? ?? 'unlisted',
      endedAt: json['ended_at'] != null
          ? DateTime.parse(json['ended_at'] as String)
          : null,
      recordedAt: json['recorded_at'] != null
          ? DateTime.parse(json['recorded_at'] as String)
          : null,
      replayUrl: json['replay_url'] as String?,
      playbackUrl: json['playback_url'] as String?,
      thumbnailUrl: json['thumbnail_url'] as String?,
      durationLabel: json['duration_label'] as String?,
      viewCount: json['view_count'] as int? ?? 0,
      viewsLabel: json['views_label'] as String?,
      downloadEnabled: json['download_enabled'] as bool? ?? false,
      youtubeWatchUrl: json['youtube_watch_url'] as String?,
      expiresAt: json['expires_at'] != null
          ? DateTime.parse(json['expires_at'] as String)
          : null,
    );
  }
}
