

class TraktIds {
  final int? trakt;
  final String? imdb;
  final int? tmdb;
  final int? tvdb;
  final String? slug;

  const TraktIds({this.trakt, this.imdb, this.tmdb, this.tvdb, this.slug});

  factory TraktIds.fromJson(Object? raw) {
    if (raw is! Map) return const TraktIds();
    final json = raw.cast<String, dynamic>();
    return TraktIds(
      trakt: (json['trakt'] as num?)?.toInt(),
      imdb: json['imdb'] as String?,
      tmdb: (json['tmdb'] as num?)?.toInt(),
      tvdb: (json['tvdb'] as num?)?.toInt(),
      slug: json['slug'] as String?,
    );
  }


  bool get hasReliableId =>
      (trakt != null && trakt! > 0) ||
      (imdb != null && imdb!.isNotEmpty) ||
      (tmdb != null && tmdb! > 0) ||
      (tvdb != null && tvdb! > 0);

  Map<String, dynamic> toJson() {
    final out = <String, dynamic>{};
    if (trakt != null && trakt! > 0) out['trakt'] = trakt;
    if (imdb != null && imdb!.isNotEmpty) out['imdb'] = imdb;
    if (tmdb != null && tmdb! > 0) out['tmdb'] = tmdb;
    if (tvdb != null && tvdb! > 0) out['tvdb'] = tvdb;
    if (slug != null && slug!.isNotEmpty) out['slug'] = slug;
    return out;
  }
}
