using Microsoft.AspNetCore.Mvc; namespace RobotNet10.RobotApp.MarkerDetection; public static class MarkerDetectionApiEndpoints { // Marker Detection Control API public static IEndpointRouteBuilder MapMarkerDetectionApiEndpoints(this IEndpointRouteBuilder app) { var markerApi = app.MapGroup("/api/marker-detection").DisableAntiforgery(); // Enable or disable marker detection markerApi.MapPost("/detection/enable", async (HttpRequest request, [FromServices] MarkerDetectionIntegrationService service) => { try { var body = await request.ReadFromJsonAsync>(); var enable = body?["enable"] ?? true; service.SetEnableDetection(enable); return Results.Ok(new { status = "success", message = $"Marker detection {(enable ? "enabled" : "disabled")}", enabled = enable }); } catch (Exception ex) { return Results.BadRequest(new { status = "error", message = ex.Message }); } }); // Get current marker pose markerApi.MapGet("/pose/current", ([FromServices] MarkerDetectionIntegrationService service) => { try { var pose = service.GetMarkerPose(); if (pose == null) return Results.NotFound(new { status = "error", message = "No marker pose available" }); return Results.Ok(new { status = "success", pose = new { header = new { seq = pose.Header.Seq, stamp = pose.Header.Stamp, frameId = pose.Header.FrameId }, position = new { x = pose.Pose.Position[0], y = pose.Pose.Position[1], z = pose.Pose.Position[2] }, orientation = new { x = pose.Pose.Orientation[0], y = pose.Pose.Orientation[1], z = pose.Pose.Orientation[2], w = pose.Pose.Orientation[3] } } }); } catch (Exception ex) { return Results.BadRequest(new { status = "error", message = ex.Message }); } }); return app; } }