using GerbilManagerWebAPI.Import;
using Microsoft.AspNetCore.Http.HttpResults;

namespace GerbilManagerWebAPI.Endpoints
{
    public static class ImportDocxEndpoints
    {
        public static IEndpointRouteBuilder MapImportDocxEndpoints(this IEndpointRouteBuilder app)
        {
            var group = app.MapGroup("/import/docx").WithTags("Import");

            // POST /import/docx/dry-run — analyse without writing
            group.MapPost("/dry-run",
                async Task<Ok<ImportDocxReport>> (
                    ApplicationContext db, IConfiguration config, IWebHostEnvironment env) =>
                    TypedResults.Ok(await new ImportDocxService(db, config, env).RunAsync(execute: false)));

            // POST /import/docx/execute — GATED: enriches Gerbils with Litter-Link,
            // ReceiverContact, GoHomeDate, DateOfDeath, CauseOfDeath (fill-NULL-only).
            group.MapPost("/execute",
                async Task<Ok<ImportDocxReport>> (
                    ApplicationContext db, IConfiguration config, IWebHostEnvironment env) =>
                    TypedResults.Ok(await new ImportDocxService(db, config, env).RunAsync(execute: true)));

            return app;
        }
    }
}
