import 'package:flutter/foundation.dart';

import '../../../core/contracts/library.dart';
import '../session/playback_target.dart';


@immutable
class PlaylistItem {
  const PlaylistItem({
    required this.itemId,
    this.mediaSourceId,
    this.startPositionTicks,
    this.preferredAudioStreamIndex,
    this.preferredSubtitleStreamIndex,
    this.serverId,
    this.serverIdentity,
    this.displayLabel = '',
    this.playFromStart = false,
    this.preloadedItem,
  });

  final String itemId;
  final String? mediaSourceId;
  final int? startPositionTicks;
  final int? preferredAudioStreamIndex;
  final int? preferredSubtitleStreamIndex;


  final String? serverId;


  final PlaybackServerIdentity? serverIdentity;


  final String displayLabel;


  final bool playFromStart;


  final EmbyRawItem? preloadedItem;

  @override
  bool operator ==(Object other) =>
      other is PlaylistItem &&
      other.itemId == itemId &&
      other.mediaSourceId == mediaSourceId &&
      other.startPositionTicks == startPositionTicks &&
      other.preferredAudioStreamIndex == preferredAudioStreamIndex &&
      other.preferredSubtitleStreamIndex == preferredSubtitleStreamIndex &&
      other.serverId == serverId &&
      other.serverIdentity == serverIdentity &&
      other.displayLabel == displayLabel &&
      other.playFromStart == playFromStart &&
      other.preloadedItem == preloadedItem;

  @override
  int get hashCode => Object.hash(
    itemId,
    mediaSourceId,
    startPositionTicks,
    preferredAudioStreamIndex,
    preferredSubtitleStreamIndex,
    serverId,
    serverIdentity,
    displayLabel,
    playFromStart,
    preloadedItem,
  );

  @override
  String toString() =>
      'PlaylistItem(itemId=$itemId, serverId=$serverId, label=$displayLabel)';
}


abstract class Playlist {

  ValueListenable<PlaylistItem> get current;


  ValueListenable<int> get currentIndex;

  int get length;
  bool get hasNext;
  bool get hasPrev;

  Future<void> next();
  Future<void> prev();
  Future<void> goTo(int index);
  Future<void> goToItemId(String itemId);
  void dispose();
}
