using System;
using System.Collections.Generic;
using EventsAppQuest.Application.Services;
using EventsAppQuest.Infrastructure.Services;
using UnityEngine;


namespace EventsAppQuest.Core
{
    /// <summary>
    /// Registro e resolucao de servicos (container simples para injecao de dependencias).
    /// </summary>
    public class ServiceRegistry
    {
        private static ServiceRegistry _instance;
        private readonly Dictionary<Type, object> _services = new Dictionary<Type, object>();

        /// <summary>Instancia global do registro (acesso apos bootstrap).</summary>
        public static ServiceRegistry Instance => _instance ??= new ServiceRegistry();

        /// <summary>Registra uma instancia para um tipo.</summary>
        public void Register<T>(T instance) where T : class
        {
            if (instance == null) throw new ArgumentNullException(nameof(instance));
            _services[typeof(T)] = instance;
        }

        /// <summary>Obtem servico registrado.</summary>
        public T Get<T>() where T : class
        {
            if (_services.TryGetValue(typeof(T), out var obj))
                return (T)obj;
            Debug.LogWarning($"[ServiceRegistry] No service registered for {typeof(T).Name}");
            return null;
        }

        /// <summary>Reseta a instancia (util em testes ou reinicio).</summary>
        public static void Reset()
        {
            _instance = null;
        }

        /// <summary>Registra servicos mock quando UseMockServices e true.</summary>
        public void RegisterMockServices()
        {
            Register<IEventCategoryService>(new MockEventCategoryService());
            Register<ISpaceService>(new MockSpaceService());
            Register<ISupplierService>(new MockSupplierService());
            Register<ITemplateService>(new MockTemplateService());
            Register<IShowroomService>(new MockShowroomService());
            Register<IProposalPricingService>(new MockProposalPricingService());
            Register<ISpaceLayoutService>(new MockSpaceLayoutService());
            Register<IPlacementCompatibilityService>(new MockPlacementCompatibilityService());
            Register<ILayoutPresetService>(new MockLayoutPresetService());
            Register<IVisualThemeService>(new MockVisualThemeService());
            Register<IProposalPresentationService>(new MockProposalPresentationService());
            Register<IProposalReviewService>(new MockProposalReviewService());
            Register<IProposalFitScoringService>(new MockProposalFitScoringService());
            Register<ISpaceCapacityEvaluationService>(new MockSpaceCapacityEvaluationService());
            Register<IEventFlowEvaluationService>(new MockEventFlowEvaluationService());
            Register<IEventSetupTimelineService>(new MockEventSetupTimelineService());
            Register<ISupplierCoverageEvaluationService>(new MockSupplierCoverageEvaluationService());
            Register<ICommercialPackageService>(new MockCommercialPackageService());
            Register<IEventMomentPlanningService>(new MockEventMomentPlanningService());
            Register<IEventMomentTransitionService>(new MockEventMomentTransitionService());
            Register<IProposalGuidedTourService>(new MockProposalGuidedTourService());
            Register<IProposalVisualHotspotService>(new MockProposalVisualHotspotService());
            Register<IProposalSceneStateService>(new MockProposalSceneStateService());
            Register<IProposalTemporalComparisonService>(new MockProposalTemporalComparisonService());
            Register<IProposalRecommendationService>(new MockProposalRecommendationService());
            Register<IProposalDecisionSummaryService>(new MockProposalDecisionSummaryService());
            Register<IMRPresentationPlanningService>(new MockMRPresentationPlanningService());
            Register<IQuestRuntimeReadinessService>(new MockQuestRuntimeReadinessService());
            Register<IQuestXRRuntimeStatusService>(new MockQuestXRRuntimeStatusService());
        }
    }
}
