using AutoMapper;
using MyNewProjectName.Domain.Entities;
using MyNewProjectName.Domain.Interfaces;
using MediatR;

namespace MyNewProjectName.Application.Features.Sample.Queries.GetSamples;

/// <summary>
/// Handler for GetSamplesQuery
/// </summary>
public class GetSamplesQueryHandler : IRequestHandler<GetSamplesQuery, List<SampleDto>>
{
    private readonly IRepository<SampleEntity> _repository;
    private readonly IMapper _mapper;

    public GetSamplesQueryHandler(IRepository<SampleEntity> repository, IMapper mapper)
    {
        _repository = repository;
        _mapper = mapper;
    }

    public async Task<List<SampleDto>> Handle(GetSamplesQuery request, CancellationToken cancellationToken)
    {
        var entities = await _repository.GetAllAsync(cancellationToken);
        return _mapper.Map<List<SampleDto>>(entities);
    }
}
