using System.Collections.Generic;
using Kyoo.Models;
using TMDbLib.Objects.General;
using TMDbLib.Objects.Search;
using TvCast = TMDbLib.Objects.TvShows.Cast;
using MovieCast = TMDbLib.Objects.Movies.Cast;
namespace Kyoo.TheMovieDb
{
	/// 
	/// A class containing extensions methods to convert from TMDB's types to Kyoo's types.
	/// 
	public static partial class Convertors
	{
		/// 
		/// Convert a  to a .
		/// 
		/// An internal TheMovieDB cast.
		/// The provider that represent TheMovieDB inside Kyoo.
		/// A  representing the movie cast.
		public static PeopleRole ToPeople(this MovieCast cast, Provider provider)
		{
			return new()
			{
				People = new People
				{
					Slug = Utility.ToSlug(cast.Name),
					Name = cast.Name,
					Images = new Dictionary
					{
						[Thumbnails.Poster] = cast.ProfilePath != null 
							? $"https://image.tmdb.org/t/p/original{cast.ProfilePath}" 
							: null
					},
					ExternalIDs = new[]
					{
						new MetadataID
						{
							Provider = provider,
							DataID = cast.Id.ToString(),
							Link = $"https://www.themoviedb.org/person/{cast.Id}"
						}
					}
				},
				Type = "Actor",
				Role = cast.Character
			};
		}
		
		/// 
		/// Convert a  to a .
		/// 
		/// An internal TheMovieDB cast.
		/// The provider that represent TheMovieDB inside Kyoo.
		/// A  representing the movie cast.
		public static PeopleRole ToPeople(this TvCast cast, Provider provider)
		{
			return new()
			{
				People = new People
				{
					Slug = Utility.ToSlug(cast.Name),
					Name = cast.Name,
					Images = new Dictionary
					{
						[Thumbnails.Poster] = cast.ProfilePath != null 
							? $"https://image.tmdb.org/t/p/original{cast.ProfilePath}" 
							: null
					},
					ExternalIDs = new[]
					{
						new MetadataID
						{
							Provider = provider,
							DataID = cast.Id.ToString(),
							Link = $"https://www.themoviedb.org/person/{cast.Id}"
						}
					}
				},
				Type = "Actor",
				Role = cast.Character
			};
		}
		
		/// 
		/// Convert a  to a .
		/// 
		/// An internal TheMovieDB crew member.
		/// The provider that represent TheMovieDB inside Kyoo.
		/// A  representing the movie crew.
		public static PeopleRole ToPeople(this Crew crew, Provider provider)
		{
			return new()
			{
				People = new People
				{
					Slug = Utility.ToSlug(crew.Name),
					Name = crew.Name,
					Images = new Dictionary
					{
						[Thumbnails.Poster] = crew.ProfilePath != null 
							? $"https://image.tmdb.org/t/p/original{crew.ProfilePath}" 
							: null
					},
					ExternalIDs = new[]
					{
						new MetadataID
						{
							Provider = provider,
							DataID = crew.Id.ToString(),
							Link = $"https://www.themoviedb.org/person/{crew.Id}"
						}
					}
				},
				Type = crew.Department,
				Role = crew.Job
			};
		}
		
		/// 
		/// Convert a  to a .
		/// 
		/// An internal TheMovieDB person.
		/// The provider that represent TheMovieDB inside Kyoo.
		/// A  representing the person.
		public static People ToPeople(this SearchPerson person, Provider provider)
		{
			return new()
			{
				Slug = Utility.ToSlug(person.Name),
				Name = person.Name,
				Images = new Dictionary
				{
					[Thumbnails.Poster] = person.ProfilePath != null 
						? $"https://image.tmdb.org/t/p/original{person.ProfilePath}" 
						: null
				},
				ExternalIDs = new[]
				{
					new MetadataID
					{
						Provider = provider,
						DataID = person.Id.ToString(),
						Link = $"https://www.themoviedb.org/person/{person.Id}"
					}
				}
			};
		}
	}
}