using Microsoft.Extensions.DependencyInjection;
using ZB.MOM.WW.ScadaBridge.Communication.Grpc;

namespace ZB.MOM.WW.ScadaBridge.Communication;

public static class ServiceCollectionExtensions
{
    /// <summary>Registers communication services including options, <see cref="CommunicationService"/>, gRPC client factory, and debug stream.</summary>
    /// <param name="services">The DI service collection to register services into.</param>
    /// <returns>The same <see cref="IServiceCollection"/> to allow chaining.</returns>
    public static IServiceCollection AddCommunication(this IServiceCollection services)
    {
        services.AddOptions<CommunicationOptions>()
            .BindConfiguration("Communication");

        services.AddSingleton<CommunicationService>();
        services.AddSingleton<SiteStreamGrpcClientFactory>();
        services.AddSingleton<DebugStreamService>();

        return services;
    }

    /// <summary>Hook for registering additional DI services needed by communication actors; actor creation itself happens inside <c>AkkaHostedService</c>.</summary>
    /// <param name="services">The DI service collection to register services into.</param>
    /// <returns>The same <see cref="IServiceCollection"/> to allow chaining.</returns>
    public static IServiceCollection AddCommunicationActors(this IServiceCollection services)
    {
        // Actor registration happens in AkkaHostedService.RegisterCentralActors/RegisterSiteActors.
        // This method is a hook for any additional DI registrations needed by the communication actors.
        return services;
    }
}
