using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Monitoring.Common;
using Monitoring.Infrastructure.Abstractions;
using Monitoring.Infrastructure.Data;
using Monitoring.Infrastructure.Services;
using Monitoring.Notifications.Client;
using Monitoring.Notifications.Events;
using Monitoring.Services;
using Ping.Job;

var builder = Host.CreateApplicationBuilder(args);

var configuration = builder.Configuration;

builder
	.Services.AddScoped<NotificationSentResponse>()
	.AddScoped<IPasswordService, PasswordService>()
	.AddNotificationService()
	.AddHostedService<PingJob>();

builder.Services.AddLogging(builder => builder.AddConsole());

if (EnvironmentVariables.Has("DATABASE_ASPIRE_NAME"))
{
	var connectionName = EnvironmentVariables.Get("DATABASE_ASPIRE_NAME");
	builder.AddNpgsqlDbContext<DataContext>(connectionName: connectionName);
}
else
{
	var connectionString = EnvironmentVariables.Get("DATABASE_CONNECTION_STRING");
	builder.Services.AddNpgsql<DataContext>(connectionString);
}

builder.Services.AddNotificationClient();

var app = builder.Build();

await app.RunAsync();
