using LightlessSync.FileCache;
using LightlessSync.Interop.Ipc;
using LightlessSync.LightlessConfiguration;
using LightlessSync.PlayerData.Factories;
using LightlessSync.Services;
using LightlessSync.Services.ActorTracking;
using LightlessSync.Services.Mediator;
using LightlessSync.Services.ModelDecimation;
using LightlessSync.Services.PairProcessing;
using LightlessSync.Services.ServerConfiguration;
using LightlessSync.Services.TextureCompression;
using Dalamud.Plugin.Services;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace LightlessSync.PlayerData.Pairs;

internal sealed class PairHandlerAdapterFactory : IPairHandlerAdapterFactory
{
    private readonly ILoggerFactory _loggerFactory;
    private readonly LightlessMediator _mediator;
    private readonly PairManager _pairManager;
    private readonly GameObjectHandlerFactory _gameObjectHandlerFactory;
    private readonly IpcManager _ipcManager;
    private readonly FileDownloadManagerFactory _fileDownloadManagerFactory;
    private readonly PluginWarningNotificationService _pluginWarningNotificationManager;
    private readonly IServiceProvider _serviceProvider;
    private readonly IHostApplicationLifetime _lifetime;
    private readonly FileCacheManager _fileCacheManager;
    private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
    private readonly PlayerPerformanceService _playerPerformanceService;
    private readonly PairProcessingLimiter _pairProcessingLimiter;
    private readonly ServerConfigurationManager _serverConfigManager;
    private readonly TextureDownscaleService _textureDownscaleService;
    private readonly ModelDecimationService _modelDecimationService;
    private readonly PairStateCache _pairStateCache;
    private readonly PairPerformanceMetricsCache _pairPerformanceMetricsCache;
    private readonly PenumbraTempCollectionJanitor _tempCollectionJanitor;
    private readonly LightlessConfigService _configService;
    private readonly XivDataAnalyzer _modelAnalyzer;
    private readonly IFramework _framework;

    public PairHandlerAdapterFactory(
        ILoggerFactory loggerFactory,
        LightlessMediator mediator,
        PairManager pairManager,
        GameObjectHandlerFactory gameObjectHandlerFactory,
        IpcManager ipcManager,
        FileDownloadManagerFactory fileDownloadManagerFactory,
        PluginWarningNotificationService pluginWarningNotificationManager,
        IServiceProvider serviceProvider,
        IFramework framework,
        IHostApplicationLifetime lifetime,
        FileCacheManager fileCacheManager,
        PlayerPerformanceConfigService playerPerformanceConfigService,
        PlayerPerformanceService playerPerformanceService,
        PairProcessingLimiter pairProcessingLimiter,
        ServerConfigurationManager serverConfigManager,
        TextureDownscaleService textureDownscaleService,
        ModelDecimationService modelDecimationService,
        PairStateCache pairStateCache,
        PairPerformanceMetricsCache pairPerformanceMetricsCache,
        PenumbraTempCollectionJanitor tempCollectionJanitor,
        XivDataAnalyzer modelAnalyzer,
        LightlessConfigService configService)
    {
        _loggerFactory = loggerFactory;
        _mediator = mediator;
        _pairManager = pairManager;
        _gameObjectHandlerFactory = gameObjectHandlerFactory;
        _ipcManager = ipcManager;
        _fileDownloadManagerFactory = fileDownloadManagerFactory;
        _pluginWarningNotificationManager = pluginWarningNotificationManager;
        _serviceProvider = serviceProvider;
        _framework = framework;
        _lifetime = lifetime;
        _fileCacheManager = fileCacheManager;
        _playerPerformanceConfigService = playerPerformanceConfigService;
        _playerPerformanceService = playerPerformanceService;
        _pairProcessingLimiter = pairProcessingLimiter;
        _serverConfigManager = serverConfigManager;
        _textureDownscaleService = textureDownscaleService;
        _modelDecimationService = modelDecimationService;
        _pairStateCache = pairStateCache;
        _pairPerformanceMetricsCache = pairPerformanceMetricsCache;
        _tempCollectionJanitor = tempCollectionJanitor;
        _modelAnalyzer = modelAnalyzer;
        _configService = configService;
    }

    public IPairHandlerAdapter Create(string ident)
    {
        var downloadManager = _fileDownloadManagerFactory.Create();
        var dalamudUtilService = _serviceProvider.GetRequiredService<DalamudUtilService>();
        var actorObjectService = _serviceProvider.GetRequiredService<ActorObjectService>();
        return new PairHandlerAdapter(
            _loggerFactory.CreateLogger<PairHandlerAdapter>(),
            _mediator,
            _pairManager,
            ident,
            _gameObjectHandlerFactory,
            _ipcManager,
            downloadManager,
            _pluginWarningNotificationManager,
            dalamudUtilService,
            _framework,
            actorObjectService,
            _lifetime,
            _fileCacheManager,
            _playerPerformanceConfigService,
            _playerPerformanceService,
            _pairProcessingLimiter,
            _serverConfigManager,
            _textureDownscaleService,
            _modelDecimationService,
            _pairStateCache,
            _pairPerformanceMetricsCache,
            _tempCollectionJanitor,
            _modelAnalyzer,
            _configService);
    }
}
