using System.Collections.Generic;
using System.Linq;
using IdentityServer4.Models;
namespace Kyoo.Authentication
{
	/// 
	/// The hard coded context of the identity server.
	/// 
	public static class IdentityContext
	{
		/// 
		/// The list of identity resources supported (email, profile and openid)
		/// 
		/// The list of identity resources supported
		public static IEnumerable GetIdentityResources()
		{
			return new List
			{
				new IdentityResources.OpenId(),
				new IdentityResources.Email(),
				new IdentityResources.Profile()
			};
		}
		/// 
		/// The list of officially supported clients.
		/// 
		/// 
		/// You can add custom clients in the settings.json file.
		/// 
		/// The list of officially supported clients.
		public static IEnumerable GetClients()
		{
			return new List
			{
				new()
				{
					ClientId = "kyoo.webapp",
					AccessTokenType = AccessTokenType.Jwt,
					AllowedGrantTypes = GrantTypes.Code,
					RequirePkce = true,
					RequireClientSecret = false,
					
					AllowAccessTokensViaBrowser = true,
					AllowOfflineAccess = true,
					RequireConsent = false,
					
					AllowedScopes = { "openid", "profile", "kyoo.read", "kyoo.write", "kyoo.play", "kyoo.admin" },
					RedirectUris =  { "/", "/silent.html" },
					PostLogoutRedirectUris = { "/logout" }
				}
			};
		}
		/// 
		/// The list of scopes supported by the API.
		/// 
		/// The list of scopes
		public static IEnumerable GetScopes()
		{
			return new[]
			{
				new ApiScope
				{
					Name = "kyoo.read",
					DisplayName = "Read only access to the API.",
				},
				new ApiScope
				{
					Name = "kyoo.write",
					DisplayName = "Read and write access to the public API"
				},
				new ApiScope
				{
					Name = "kyoo.play",
					DisplayName = "Allow playback of movies and episodes."
				},
				new ApiScope
				{
					Name = "kyoo.admin",
					DisplayName = "Full access to the admin's API and the public API."
				}
			};
		}
		
		/// 
		/// The list of APIs (this is used to create Audiences)
		/// 
		/// The list of apis
		public static IEnumerable GetApis()
		{
			return new[]
			{
				new ApiResource("kyoo", "Kyoo")
				{
					Scopes = GetScopes().Select(x => x.Name).ToArray()
				}
			};
		}
	}
}