using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using Kyoo.Common.Models.Attributes;
using Kyoo.Controllers;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
{
///
/// A series or a movie.
///
public class Show : IResource, IOnMerge
{
///
public int ID { get; set; }
///
public string Slug { get; set; }
///
/// The title of this show.
///
public string Title { get; set; }
///
/// The list of alternative titles of this show.
///
[EditableRelation] public string[] Aliases { get; set; }
///
/// The path of the root directory of this show.
/// This can be any kind of path supported by
///
[SerializeIgnore] public string Path { get; set; }
///
/// The summary of this show.
///
public string Overview { get; set; }
///
/// Is this show airing, not aired yet or finished?
///
public Status Status { get; set; }
///
/// An URL to a trailer. This could be any path supported by the .
///
/// TODO for now, this is set to a youtube url. It should be cached and converted to a local file.
public string TrailerUrl { get; set; }
///
/// The date this show started airing. It can be null if this is unknown.
///
public DateTime? StartAir { get; set; }
///
/// The date this show finished airing.
/// It must be after the but can be the same (example: for movies).
/// It can also be null if this is unknown.
///
public DateTime? EndAir { get; set; }
///
/// The path of this show's poster.
/// By default, the http path for this poster is returned from the public API.
/// This can be disabled using the internal query flag.
///
[SerializeAs("{HOST}/api/shows/{Slug}/poster")] public string Poster { get; set; }
///
/// The path of this show's logo.
/// By default, the http path for this logo is returned from the public API.
/// This can be disabled using the internal query flag.
///
[SerializeAs("{HOST}/api/shows/{Slug}/logo")] public string Logo { get; set; }
///
/// The path of this show's backdrop.
/// By default, the http path for this backdrop is returned from the public API.
/// This can be disabled using the internal query flag.
///
[SerializeAs("{HOST}/api/shows/{Slug}/backdrop")] public string Backdrop { get; set; }
///
/// True if this show represent a movie, false otherwise.
///
public bool IsMovie { get; set; }
///
/// The link to metadata providers that this show has. See for more information.
///
[EditableRelation] [LoadableRelation] public ICollection> ExternalIDs { get; set; }
///
/// The ID of the Studio that made this show.
///
[SerializeIgnore] public int? StudioID { get; set; }
///
/// The Studio that made this show. This must be explicitly loaded via a call to .
///
[LoadableRelation(nameof(StudioID))] [EditableRelation] public Studio Studio { get; set; }
///
/// The list of genres (themes) this show has.
///
[LoadableRelation] [EditableRelation] public ICollection Genres { get; set; }
///
/// The list of people that made this show.
///
[LoadableRelation] [EditableRelation] public ICollection People { get; set; }
///
/// The different seasons in this show. If this is a movie, this list is always null or empty.
///
[LoadableRelation] public ICollection Seasons { get; set; }
///
/// The list of episodes in this show.
/// If this is a movie, there will be a unique episode (with the seasonNumber and episodeNumber set to null).
/// Having an episode is necessary to store metadata and tracks.
///
[LoadableRelation] public ICollection Episodes { get; set; }
///
/// The list of libraries that contains this show.
///
[LoadableRelation] public ICollection Libraries { get; set; }
///
/// The list of collections that contains this show.
///
[LoadableRelation] public ICollection Collections { get; set; }
#if ENABLE_INTERNAL_LINKS
///
/// The internal link between this show and libraries in the list.
///
[Link] public ICollection> LibraryLinks { get; set; }
///
/// The internal link between this show and collections in the list.
///
[Link] public ICollection> CollectionLinks { get; set; }
///
/// The internal link between this show and genres in the list.
///
[Link] public ICollection> GenreLinks { get; set; }
#endif
///
/// Retrieve the internal provider's ID of a show using it's provider slug.
///
/// This method will never return anything if the are not loaded.
/// The slug of the provider
/// The field of the asked provider.
[CanBeNull]
public string GetID(string provider)
{
return ExternalIDs?.FirstOrDefault(x => x.Second.Slug == provider)?.DataID;
}
///
public void OnMerge(object merged)
{
if (ExternalIDs != null)
foreach (MetadataID id in ExternalIDs)
id.First = this;
if (People != null)
foreach (PeopleRole link in People)
link.Show = this;
if (Seasons != null)
foreach (Season season in Seasons)
season.Show = this;
if (Episodes != null)
foreach (Episode episode in Episodes)
episode.Show = this;
}
}
///
/// The enum containing show's status.
///
public enum Status { Finished, Airing, Planned, Unknown }
}