using SnykRestApi.Models;
using SnykRestApi.Repositories;
using SnykRestApi.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace SnykRestApi
{
    class Program
    {
        static Task Main(string[] args) =>
                CreateHostBuilder(args).Build().RunAsync();

        static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureServices((builder, services) =>
                {
                    IConfiguration config = new ConfigurationBuilder()
                            .AddJsonFile("appsettings.json")
                            .AddEnvironmentVariables()
                            .Build();

                    Settings settings = config.GetRequiredSection("Settings").Get<Settings>();

                    services.AddSingleton<AccessTokenRepository>();
                    services.AddSingleton(settings);

                    services.AddHttpClient<OrganizationRepository>();
                    services.AddHttpClient<AuditLogRepository>();
                    services.AddHttpClient<ProjectRepository>();
                    services.AddHttpClient<UserRepository>();
                    services.AddTransient<CsvRepository>();

                    services.AddScoped<AuditLogService>();

                    services.AddHostedService<OptionService>();
                });
    }
}