using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using Kyoo.Abstractions.Models.Attributes;
namespace Kyoo.Abstractions.Models
{
	/// 
	/// The type of item, ether a show, a movie or a collection.
	/// 
	public enum ItemType
	{
		Show,
		Movie,
		Collection
	}
	/// 
	/// A type union between  and .
	/// This is used to list content put inside a library.
	/// 
	public class LibraryItem : IResource, IThumbnails
	{
		/// 
		public int ID { get; set; }
		/// 
		public string Slug { get; set; }
		/// 
		/// The title of the show or collection.
		/// 
		public string Title { get; set; }
		/// 
		/// The summary of the show or collection.
		/// 
		public string Overview { get; set; }
		/// 
		/// Is this show airing, not aired yet or finished? This is only applicable for shows.
		/// 
		public Status? Status { get; set; }
		/// 
		/// The date this show or collection started airing. It can be null if this is unknown. 
		/// 
		public DateTime? StartAir { get; set; }
		/// 
		/// The date this show or collection 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; }
		/// 
		public Dictionary Images { get; set; }
		/// 
		/// The path of this item'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/{Type:l}/{Slug}/poster")]
		public string Poster => Images?.GetValueOrDefault(Models.Images.Poster);
		/// 
		/// The type of this item (ether a collection, a show or a movie).
		/// 
		public ItemType Type { get; set; }
		/// 
		/// Create a new, empty .
		/// 
		public LibraryItem() { }
		/// 
		/// Create a  from a show.
		/// 
		/// The show that this library item should represent.
		public LibraryItem(Show show)
		{
			ID = show.ID;
			Slug = show.Slug;
			Title = show.Title;
			Overview = show.Overview;
			Status = show.Status;
			StartAir = show.StartAir;
			EndAir = show.EndAir;
			Images = show.Images;
			Type = show.IsMovie ? ItemType.Movie : ItemType.Show;
		}
		/// 
		/// Create a  from a collection
		/// 
		/// The collection that this library item should represent.
		public LibraryItem(Collection collection)
		{
			ID = -collection.ID;
			Slug = collection.Slug;
			Title = collection.Name;
			Overview = collection.Overview;
			Status = Models.Status.Unknown;
			StartAir = null;
			EndAir = null;
			Images = collection.Images;
			Type = ItemType.Collection;
		}
		/// 
		/// An expression to create a  representing a show.
		/// 
		public static Expression> FromShow => x => new LibraryItem
		{
			ID = x.ID,
			Slug = x.Slug,
			Title = x.Title,
			Overview = x.Overview,
			Status = x.Status,
			StartAir = x.StartAir,
			EndAir = x.EndAir,
			Images = x.Images,
			Type = x.IsMovie ? ItemType.Movie : ItemType.Show
		};
		/// 
		/// An expression to create a  representing a collection.
		/// 
		public static Expression> FromCollection => x => new LibraryItem
		{
			ID = -x.ID,
			Slug = x.Slug,
			Title = x.Name,
			Overview = x.Overview,
			Status = Models.Status.Unknown,
			StartAir = null,
			EndAir = null,
			Images = x.Images,
			Type = ItemType.Collection
		};
	}
}