using System;
using System.Collections.Generic;

namespace CounterDrone.Core.Algorithms
{
    /// <summary>算法工厂 — 统一管理算法组件的创建与替换</summary>
    public static class AlgorithmFactory
    {
        private static readonly Dictionary<Type, Func<object>> _registry = new()
        {
            [typeof(ICloudDispersionModel)] = () => new GaussianPuffDispersion(),
            [typeof(IDamageModel)] = () => new DamageModelRouter(),
        };

        public static void Register<TInterface>(Func<object> factory)
        {
            _registry[typeof(TInterface)] = factory;
        }

        public static T Create<T>() where T : class
        {
            if (_registry.TryGetValue(typeof(T), out var factory))
                return (T)factory();
            throw new InvalidOperationException($"No implementation for {typeof(T).Name}");
        }
    }
}
