class PlayerStatus {
  const PlayerStatus({
    required this.running,
    required this.paused,
    required this.inTransition,
    required this.currentIndex,
    required this.playlistLength,
    this.currentVideo,
  });

  final bool running;
  final bool paused;
  final bool inTransition;
  final int currentIndex;
  final int playlistLength;
  final String? currentVideo;

  factory PlayerStatus.initial() {
    return const PlayerStatus(
      running: false,
      paused: false,
      inTransition: false,
      currentIndex: 0,
      playlistLength: 0,
      currentVideo: null,
    );
  }

  factory PlayerStatus.fromJson(Map<String, dynamic> json) {
    return PlayerStatus(
      running: json['running'] as bool? ?? false,
      paused: json['paused'] as bool? ?? false,
      inTransition: json['in_transition'] as bool? ?? false,
      currentIndex: json['current_index'] as int? ?? 0,
      playlistLength: json['playlist_length'] as int? ?? 0,
      currentVideo: json['current_video'] as String?,
    );
  }

  Map<String, dynamic> toJson() {
    return <String, dynamic>{
      'running': running,
      'paused': paused,
      'in_transition': inTransition,
      'current_index': currentIndex,
      'playlist_length': playlistLength,
      'current_video': currentVideo,
    };
  }

  PlayerStatus copyWith({
    bool? running,
    bool? paused,
    bool? inTransition,
    int? currentIndex,
    int? playlistLength,
    String? currentVideo,
  }) {
    return PlayerStatus(
      running: running ?? this.running,
      paused: paused ?? this.paused,
      inTransition: inTransition ?? this.inTransition,
      currentIndex: currentIndex ?? this.currentIndex,
      playlistLength: playlistLength ?? this.playlistLength,
      currentVideo: currentVideo ?? this.currentVideo,
    );
  }
}
