using ClipForge.Contracts.Requests; using ClipForge.Core.Interfaces.Services; using ClipForge.Workers.Jobs; using Hangfire; namespace ClipForge.Api.Endpoints; public static class PipelineEndpoints { public static void MapPipelineEndpoints(this WebApplication app) { var group = app.MapGroup("/api/pipeline").WithTags("Pipeline"); // Run full pipeline in background (Hangfire) group.MapPost("/run", (FullPipelineRequest request, IBackgroundJobClient backgroundJobs) => { backgroundJobs.Enqueue(job => job.ExecuteAsync(request.Niche, request.Platform, "francisca")); return Results.Accepted(value: new { Message = "Pipeline scheduled", Niche = request.Niche, Platform = request.Platform }); }); // Schedule recurring pipeline group.MapPost("/schedule", async (SchedulePipelineRequest request, ISchedulerService scheduler) => { if (string.IsNullOrEmpty(request.CronExpression)) return Results.BadRequest(new { Error = "CronExpression is required for scheduling" }); await scheduler.ScheduleRecurringGenerationAsync(request.Niche, request.CronExpression, request.Platform); return Results.Ok(new { Message = "Recurring pipeline scheduled", Niche = request.Niche, Cron = request.CronExpression }); }); // Cancel recurring job group.MapDelete("/schedule/{jobId}", async (string jobId, ISchedulerService scheduler) => { await scheduler.CancelRecurringJobAsync(jobId); return Results.Ok(new { Message = $"Job '{jobId}' cancelled" }); }); // Run full pipeline synchronously (for testing) group.MapPost("/run-sync", async (FullPipelineRequest request, FullPipelineJob job) => { await job.ExecuteAsync(request.Niche, request.Platform, request.VoiceId); return Results.Ok(new { Message = "Pipeline completed", Niche = request.Niche }); }); } }