using Microsoft.Extensions.DependencyInjection;

namespace ScadaLink.DeploymentManager;

public static class ServiceCollectionExtensions
{
    /// <summary>
    /// Configuration section that <see cref="DeploymentManagerOptions"/> is bound to.
    /// The Host binds this section to <c>appsettings.json</c> (see
    /// <c>Program.cs</c>); component libraries do not depend on
    /// <c>IConfiguration</c> directly, consistent with the Options-pattern
    /// convention enforced by <c>OptionsTests</c>.
    /// </summary>
    public const string OptionsSection = "ScadaLink:DeploymentManager";

    /// <summary>
    /// Registers the Deployment Manager services. <see cref="DeploymentManagerOptions"/>
    /// is registered via <see cref="OptionsServiceCollectionExtensions.AddOptions"/> so
    /// <c>IOptions&lt;DeploymentManagerOptions&gt;</c> is always resolvable; the Host
    /// binds <see cref="OptionsSection"/> to configuration so the operation-lock and
    /// artifact-deployment timeouts are tunable via <c>appsettings.json</c>.
    /// </summary>
    public static IServiceCollection AddDeploymentManager(this IServiceCollection services)
    {
        // DeploymentManager-008: ensure the options class is always resolvable.
        // The Host binds OptionsSection to appsettings.json; absent that binding
        // the declared option-class defaults apply.
        services.AddOptions<DeploymentManagerOptions>();
        services.AddSingleton<OperationLockManager>();
        services.AddScoped<IFlatteningPipeline, FlatteningPipeline>();
        services.AddScoped<DeploymentService>();
        services.AddScoped<ArtifactDeploymentService>();
        return services;
    }

    public static IServiceCollection AddDeploymentManagerActors(this IServiceCollection services)
    {
        // Akka actor registration is handled by Host component during actor system startup
        return services;
    }
}
