using Backend.Contracts;
using Backend.Data;
using Microsoft.EntityFrameworkCore;

namespace Backend.Endpoints;

public static partial class AdminSeasonManagementEndpoints
{
    private static async Task<IResult> GetSeasons(AwardsDbContext db)
    {
        var seasons = await db.Seasons
            .AsNoTracking()
            .OrderByDescending(item => item.Year)
            .Select(item => new AdminSeasonListItemDto(
                item.Id,
                item.Year,
                item.Name,
                item.CurrentPhase,
                item.IsCurrent,
                item.IsDemo,
                item.Categories.Count,
                item.WinnersPublishedAt,
                item.WinnersPublishedByTwitchId))
            .ToArrayAsync();

        return Results.Ok(seasons);
    }
}
