using Knot.Modules.WebRtc.Application.WebRtc.Queries;
using Knot.Shared.Kernel;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;

namespace Knot.Modules.WebRtc.Presentation.Endpoints;

/// <summary>
/// Endpoints for WebRTC signaling and ICE configuration
/// </summary>
public static class WebRtcEndpoints
{
    public static void MapWebRtcEndpoints(this WebApplication app)
    {
        var group = app.MapGroup("api/webrtc")
            .RequireAuthorization();

        group.MapGet("/ice-servers", async (ISender sender, CancellationToken ct) =>
        {
            var result = await sender.Send(new GetIceServersQuery(), ct);
            return result.IsSuccess ? Results.Ok(result.Value) : Results.BadRequest(result.Error);
        })
        .WithName("GetIceServers")
        .WithOpenApi();
    }
}