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

namespace AzureRestApi
{
    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<AzureSubscriptionRepository>();
                    services.AddHttpClient<AzureDeploymentRepository>();
                    services.AddHttpClient<AzureResourceRepository>();
                    services.AddHttpClient<AzureTagRepository>();
                    services.AddHttpClient<AzureResourceGroupRepository>();                    

                    services.AddScoped<CreatedOnDateService>();
                    services.AddScoped<DeploymentTypeService>();

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