using MassTransit;

using Microsoft.Extensions.DependencyInjection;

using Monitoring.Common;
using Monitoring.Notifications.Events;

namespace Monitoring.Notifications.Client;

public static class DependencyInjectionExtensions
{
	public static void AddNotificationClient(
		this IServiceCollection services)
	{
		services.AddMassTransit(config =>
		{
			config.AddRequestClient<NotificationSent>(new Uri("queue:notification-sent"));

			config.SetKebabCaseEndpointNameFormatter();

			config.UsingRabbitMq(
				(context, cfg) =>
				{
					cfg.Host(
						EnvironmentVariables.Get("MESSAGE_QUEUE_URL"),
						h =>
						{
							h.Username(EnvironmentVariables.Get("MESSAGE_QUEUE_USERNAME"));
							h.Password(EnvironmentVariables.Get("MESSAGE_QUEUE_PASSWORD"));
						}
					);
				}
			);
		});
	}

}
