using Microsoft.EntityFrameworkCore;
using WebApp.Data;
using WebApp.Mapping;

namespace WebApp.Endpoints;

public static class SkillsEndpoints
{
    const string GetSkillEndpointName = "GetSkill";

    public static RouteGroupBuilder MapSkillsEndpoints(this WebApplication app)
    {
        var group = app.MapGroup("api/skills").WithParameterValidation();

        // GET /skills
        group.MapGet("/",
            async (ApplicationDbContext dbContext) =>
            await dbContext.Skills
                           .OrderBy(Sk => Sk.SkillId)
                           .Select(Sk => Sk.ToSkillSummaryDto()) // SkillSummaryDto
                           .AsNoTracking()
                           .ToListAsync());

        return group;
    }
}
