using Microsoft.Extensions.Configuration;
using ZB.MOM.WW.Configuration;

namespace ZB.MOM.WW.MxGateway.Server.Configuration;

public static class GatewayConfigurationServiceCollectionExtensions
{
    /// <summary>Registers gateway configuration services in the dependency injection container.</summary>
    /// <param name="services">The service collection.</param>
    /// <param name="configuration">The configuration to bind gateway options from.</param>
    /// <returns>The service collection for chaining.</returns>
    public static IServiceCollection AddGatewayConfiguration(
        this IServiceCollection services, IConfiguration configuration)
    {
        services.AddValidatedOptions<GatewayOptions, GatewayOptionsValidator>(
            configuration, GatewayOptions.SectionName);

        services.AddSingleton<IGatewayConfigurationProvider, GatewayConfigurationProvider>();

        return services;
    }
}
