using Prism.Ioc;
using Prism.Modularity;
using System.Resources;
using XP.Common.Localization;
using XP.Common.Localization.Interfaces;
using XP.Hardware.Detector.Factories;
using XP.Hardware.Detector.Services;

namespace XP.Hardware.Detector.Module
{
    /// <summary>
    /// 探测器模块 | Detector Module
    /// Prism 模块入口，注册服务/工厂/事件到 Unity 容器 | Prism module entry, register services/factories/events to Unity container
    /// </summary>
    [Module(ModuleName = "DetectorModule")]
    public class DetectorModule : IModule
    {
        /// <summary>
        /// 模块初始化 | Module initialization
        /// </summary>
        public void OnInitialized(IContainerProvider containerProvider)
        {
            // 注册模块级多语言资源到 Fallback Chain | Register module-level localization resources to Fallback Chain
            var localizationService = containerProvider.Resolve<ILocalizationService>();
            var resourceManager = new ResourceManager(
                "XP.Hardware.Detector.Resources.Resources",
                typeof(DetectorModule).Assembly);
            localizationService.RegisterResourceSource("XP.Hardware.Detector", resourceManager);

            // 初始化 LocalizationHelper，使其通过 ILocalizationService 获取字符串（支持 Fallback Chain）
            // Initialize LocalizationHelper to use ILocalizationService for string lookup (supports Fallback Chain)
            LocalizationHelper.Initialize(localizationService);

            System.Console.WriteLine("[DetectorModule] 模块已初始化 | Module initialized");
        }

        /// <summary>
        /// 注册类型到 DI 容器 | Register types to DI container
        /// </summary>
        public void RegisterTypes(IContainerRegistry containerRegistry)
        {
            // 注册工厂层（Transient）| Register factory layer (Transient)
            containerRegistry.Register<IDetectorFactory, DetectorFactory>();

            // 注册服务层（Singleton）| Register service layer (Singleton)
            containerRegistry.RegisterSingleton<IDetectorService, DetectorService>();

            // 注册图像服务（Singleton）| Register image service (Singleton)
            containerRegistry.RegisterSingleton<IImageService, ImageService>();

            System.Console.WriteLine("[DetectorModule] 类型注册完成 | Type registration completed");
        }
    }
}
