using Microsoft.AspNetCore.Mvc;
using Predictalytics.Application.Services;

namespace Predictalytics.Api.Endpoints;

public static class WatchlistEndpoints
{
    public static void MapWatchlistEndpoints(this IEndpointRouteBuilder routes)
    {
        var group = routes.MapGroup("/api/watchlist").WithTags("Watchlist");

        group.MapGet("/", async (WatchlistService svc, CancellationToken ct) =>
        {
            var list = await svc.GetAllAsync(ct);
            return Results.Ok(list.Select(w => new
            {
                w.TraderId,
                DisplayName = w.Trader?.DisplayName ?? "?",
                PlatformUserId = w.Trader?.PlatformUserId ?? "",
                Platform = w.Trader?.Platform.ToString() ?? "Unknown",
                TotalPnl = w.Trader?.TotalPnl ?? 0,
                WinRate = w.Trader?.WinRate ?? 0,
                CopytradingScore = w.Trader?.Analytics?.CopytradingScore ?? 0,
                w.Label,
                w.Notes,
                CreatedAt = w.AddedAt
            }));
        });
    }
}
