using Microsoft.Extensions.DependencyInjection;
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Flattening;
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Services;
using ZB.MOM.WW.ScadaBridge.TemplateEngine.Validation;

namespace ZB.MOM.WW.ScadaBridge.TemplateEngine;

public static class ServiceCollectionExtensions
{
    /// <summary>
    /// Registers all template engine services (template, flattening, validation, and domain services).
    /// </summary>
    /// <param name="services">The service collection to register into.</param>
    /// <returns>The same <paramref name="services"/> instance for chaining.</returns>
    public static IServiceCollection AddTemplateEngine(this IServiceCollection services)
    {
        services.AddScoped<TemplateService>();
        services.AddScoped<SharedScriptService>();

        // Flattening services (stateless utilities)
        services.AddTransient<FlatteningService>();
        services.AddTransient<DiffService>();
        services.AddTransient<RevisionHashService>();

        // Validation services (stateless utilities)
        services.AddTransient<ScriptCompiler>();
        services.AddTransient<SemanticValidator>();
        services.AddTransient<ValidationService>();

        // Domain services (depend on scoped DbContext / repositories)
        services.AddScoped<InstanceService>();
        services.AddScoped<SiteService>();
        services.AddScoped<AreaService>();
        services.AddScoped<TemplateFolderService>();
        services.AddScoped<TemplateDeletionService>();

        // Note: CycleDetector, CollisionDetector, LockEnforcer, and TemplateResolver
        // are static utility classes and do not require DI registration.

        return services;
    }

    /// <summary>
    /// Registers Akka.NET actors for the template engine (placeholder for future actor registration).
    /// </summary>
    /// <param name="services">The service collection to register into.</param>
    /// <returns>The same <paramref name="services"/> instance for chaining.</returns>
    public static IServiceCollection AddTemplateEngineActors(this IServiceCollection services)
    {
        // Phase 0: placeholder for Akka actor registration
        return services;
    }
}
