using Microsoft.Extensions.DependencyInjection;

namespace TelegramSender;
public static class DependencyInjectionExtensions
{
	public static IServiceCollection AddTelegramSender(
		this IServiceCollection services,
		string token,
		int batchSize,
		long chatId)
	{
		if (string.IsNullOrEmpty(token) || chatId is default(long))
		{
			services.AddScoped<INotificationBroker, FakeNotificationBroker>();
			return services;
		}

		services.AddSingleton(new TelegramSenderOptions(token, batchSize, chatId));
		services.AddHostedService<SendJob>();

		services.AddScoped<INotificationBroker, NotificationBroker>();

		services.AddSingleton<MessageHub>();

		return services;
	}
}
