using Jellyfin.Plugin.SRFPlay.Channels;
using Jellyfin.Plugin.SRFPlay.Providers;
using Jellyfin.Plugin.SRFPlay.ScheduledTasks;
using Jellyfin.Plugin.SRFPlay.Services;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Plugin.SRFPlay;

/// <summary>
/// Service registrator for dependency injection.
/// </summary>
public class ServiceRegistrator : IPluginServiceRegistrator
{
    /// <inheritdoc />
    public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
    {
        // Register services as singletons
        serviceCollection.AddSingleton<MetadataCache>();
        serviceCollection.AddSingleton<StreamUrlResolver>();
        serviceCollection.AddSingleton<ContentExpirationService>();
        serviceCollection.AddSingleton<ContentRefreshService>();
        serviceCollection.AddSingleton<CategoryService>();
        serviceCollection.AddSingleton<StreamProxyService>(); // Stream proxy service

        // Register metadata providers
        serviceCollection.AddSingleton<SRFSeriesProvider>();
        serviceCollection.AddSingleton<SRFEpisodeProvider>();
        serviceCollection.AddSingleton<SRFImageProvider>();

        // Register media source provider
        serviceCollection.AddSingleton<SRFMediaProvider>();

        // Register scheduled tasks
        serviceCollection.AddSingleton<IScheduledTask, ContentRefreshTask>();
        serviceCollection.AddSingleton<IScheduledTask, ExpirationCheckTask>();

        // Register channel - must register as IChannel interface for Jellyfin to discover it
        serviceCollection.AddSingleton<IChannel, SRFPlayChannel>();
    }
}
