using LiquidCode.Tester.Worker.Services;
using LiquidCode.Tester.Worker.Services.Isolate;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container
builder.Services.AddControllers();
builder.Services.AddOpenApi();

// Add HttpClient
builder.Services.AddHttpClient();

// Register Isolate services
builder.Services.AddSingleton<IsolateService>();
builder.Services.AddSingleton(sp =>
{
    var logger = sp.GetRequiredService<ILogger<IsolateBoxPool>>();
    var maxBoxes = builder.Configuration.GetValue<int>("Isolate:MaxBoxes", 100);
    return new IsolateBoxPool(maxBoxes, logger);
});

// Register application services
builder.Services.AddSingleton<PolygonProblemXmlParser>();
builder.Services.AddSingleton<AnswerGenerationService>();
builder.Services.AddSingleton<CheckerServiceIsolate>();
builder.Services.AddSingleton<IPackageParserService, PackageParserService>();
builder.Services.AddSingleton<IOutputCheckerService, OutputCheckerService>();
builder.Services.AddSingleton<ICallbackService, CallbackService>();

// Register Isolate compilation services
builder.Services.AddSingleton<CppCompilationServiceIsolate>();
builder.Services.AddSingleton<JavaCompilationServiceIsolate>();
builder.Services.AddSingleton<KotlinCompilationServiceIsolate>();
builder.Services.AddSingleton<CSharpCompilationServiceIsolate>();
builder.Services.AddSingleton<PythonCompilationServiceIsolate>();
builder.Services.AddSingleton<ICompilationServiceFactory, CompilationServiceFactory>();

// Register Isolate execution services
builder.Services.AddSingleton<CppExecutionServiceIsolate>();
builder.Services.AddSingleton<JavaExecutionServiceIsolate>();
builder.Services.AddSingleton<KotlinExecutionServiceIsolate>();
builder.Services.AddSingleton<CSharpExecutionServiceIsolate>();
builder.Services.AddSingleton<PythonExecutionServiceIsolate>();
builder.Services.AddSingleton<IExecutionServiceFactory, ExecutionServiceFactory>();

// Register testing service
builder.Services.AddSingleton<ITestingService, TestingService>();

var app = builder.Build();

// Configure the HTTP request pipeline
if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
}

app.MapControllers();

app.Run();