using EntKube.Provisioning.Domain;
using EntKube.Provisioning.Features.GetServices;
using EntKube.Provisioning.Features.ProvisionService;
using EntKube.Provisioning.Infrastructure;

namespace EntKube.Provisioning;

public class Program
{
    public static void Main(string[] args)
    {
        WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

        // Register provisioning services. The repository is singleton for the in-memory
        // implementation; production will use a scoped DbContext-backed repository.

        builder.Services.AddSingleton<IServiceInstanceRepository, InMemoryServiceInstanceRepository>();
        builder.Services.AddScoped<ProvisionServiceHandler>();
        builder.Services.AddOpenApi();

        WebApplication app = builder.Build();

        if (app.Environment.IsDevelopment())
        {
            app.MapOpenApi();
        }

        app.UseHttpsRedirection();

        // Map feature endpoints.

        ProvisionServiceEndpoint.Map(app);
        GetServicesEndpoint.Map(app);

        app.Run();
    }
}
