using SIGCM2.Application.Abstractions;
using SIGCM2.Application.Abstractions.Persistence;
using SIGCM2.Application.IngresosBrutos.Dtos;

namespace SIGCM2.Application.IngresosBrutos.GetHistorial;

public sealed class GetHistorialIngresosBrutosQueryHandler
    : ICommandHandler<GetHistorialIngresosBrutosQuery, IReadOnlyList<HistorialCadenaIibbDto>>
{
    private readonly IIngresosBrutosRepository _repo;

    public GetHistorialIngresosBrutosQueryHandler(IIngresosBrutosRepository repo)
    {
        _repo = repo;
    }

    public async Task<IReadOnlyList<HistorialCadenaIibbDto>> Handle(GetHistorialIngresosBrutosQuery query)
    {
        var chain = await _repo.GetHistorialAsync(query.Id);
        return IngresosBrutosMapper.ToHistorialChain(chain);
    }
}
