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

namespace SIGCM2.Application.TiposDeIva.GetHistorial;

public sealed class GetHistorialTipoDeIvaQueryHandler
    : ICommandHandler<GetHistorialTipoDeIvaQuery, IReadOnlyList<HistorialCadenaDto>>
{
    private readonly ITipoDeIvaRepository _repo;

    public GetHistorialTipoDeIvaQueryHandler(ITipoDeIvaRepository repo)
    {
        _repo = repo;
    }

    public async Task<IReadOnlyList<HistorialCadenaDto>> Handle(GetHistorialTipoDeIvaQuery query)
    {
        var chain = await _repo.GetHistorialAsync(query.Id);
        return TipoDeIvaMapper.ToHistorialChain(chain);
    }
}
