using Microsoft.Extensions.DependencyInjection;
using ScadaLink.TemplateEngine.Flattening;
using ScadaLink.TemplateEngine.Services;
using ScadaLink.TemplateEngine.Validation;

namespace ScadaLink.TemplateEngine;

public static class ServiceCollectionExtensions
{
    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;
    }

    public static IServiceCollection AddTemplateEngineActors(this IServiceCollection services)
    {
        // Phase 0: placeholder for Akka actor registration
        return services;
    }
}
