using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NBB.Messaging.Abstractions;
using NetworkResurrector.Api.Services;

namespace NetworkResurrector.Api.Extensions
{

    public static class MessagingExtensions
    {
        public static void AddMessageBus(this IServiceCollection services, IConfiguration configuration)
        {
            var enabled = configuration.GetValue<bool>("Messaging:Enabled", false);
            if (enabled)
                services.AddMessageBus().AddNatsTransport(configuration);
            else
                services.AddSingleton<IMessageBusPublisher, EmptyMessageBusPublisher>();
        }
    }
}
