using EntKube.Clusters.Domain;
using EntKube.Clusters.Features.GetClusters;
using EntKube.Clusters.Features.RegisterCluster;
using EntKube.Clusters.Infrastructure;

namespace EntKube.Clusters;

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

        // Register application services. The cluster repository is a singleton
        // for the in-memory implementation — production will use a scoped EF context.

        builder.Services.AddSingleton<IClusterRepository, InMemoryClusterRepository>();
        builder.Services.AddScoped<RegisterClusterHandler>();
        builder.Services.AddOpenApi();

        WebApplication app = builder.Build();

        // Configure the HTTP pipeline with OpenAPI for development tooling.

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

        app.UseHttpsRedirection();

        // Map feature endpoints — each feature registers its own routes.

        RegisterClusterEndpoint.Map(app);
        GetClustersEndpoint.Map(app);

        app.Run();
    }
}
