using Application.Abstractions.Messaging;
﻿using Application.Abstractions.Identity;

namespace Application.Features.Director.Roles.Get
{
    public sealed class Handler(IIdentityRoleReader roleReader) : IQueryHandler<Query, List<Response>>
    {
        public async Task<List<Response>> Handle(Query request, CancellationToken ct)
        {
            var roles = await roleReader.GetRolesAsync(ct);

            return [..roles.Select(role => new Response
            {
                ID = role.ID,
                Name = role.Name,
                ClaimsCount = role.Claims.Count
            })];
        }
    }
}