import 'package:nut_player/nut_player.dart';
import 'package:nut_player/src/model/common_player_content.dart';

class CommonProvider implements Provider {

  final PlayerContent content;

  // MARK: - Constructors

  CommonProvider({required this.content});

  factory CommonProvider.url(String urlPath, {bool isLive = false, bool isLoop = false}) {
    final ContentType content;
    if (urlPath.endsWith('m3u8')) {
      content = HlsContentType(urlPath: urlPath, isLive: isLive);
    } else {
      content = Mp4ContentType(urlPath: urlPath, isLoop: isLoop);
    }
    final playerContent = CommonPlayerContent(content: content);
    return CommonProvider(content: playerContent);
  }

  factory CommonProvider.content({
    required ContentType content,
    List<PlayerStatisticRecord> statistics = const [],
    List<PlayerSubtitleRecord> subtitles = const []
  }) {
    final playerContent = CommonPlayerContent(content: content, statistics: statistics, subtitles: subtitles);
    return CommonProvider(content: playerContent);
  }

  // MARK: - Provider

  @override
  Future<PlayerContent> retrieveContent() {
    return Future.value(content);
  }
}