using Hotline.Identity.Roles;
using Hotline.Share.Dtos.Roles;
using MapsterMapper;
using XF.Domain.Dependency;
using XF.Domain.Repository;

namespace Hotline.Application.Roles;

public class RoleAppService : IRoleAppService, IScopeDependency
{
    private readonly IRepository<Role> _roleRepository;
    private readonly IMapper _mapper;

    public RoleAppService(
        IRepository<Role> roleRepository,
        IMapper mapper)
    {
        _roleRepository = roleRepository;
        _mapper = mapper;
    }

    public async Task<IReadOnlyList<RoleDto>> QueryAsync(string keyword)
    {
        var roles = await _roleRepository.Queryable()
            .ToListAsync(d => d.DisplayName.Contains(keyword));
        return _mapper.Map<IReadOnlyList<RoleDto>>(roles);
    }
}