using ChapterX.Domain.Repositories;
using MediatR;
using Microsoft.Extensions.Logging;

namespace ChapterX.Application.AISuggestion.Queries
{
    public class GetByChapterHandler : IRequestHandler<GetByChapterRequest, GetByChapterResponse>
    {
        private readonly IAISuggestionRepository _aiSuggestionRepository;
        private readonly ILogger<GetByChapterHandler> _logger;

        public GetByChapterHandler(IAISuggestionRepository aiSuggestionRepository, ILogger<GetByChapterHandler> logger)
        {
            _aiSuggestionRepository = aiSuggestionRepository;
            _logger = logger;
        }

        public async Task<GetByChapterResponse> Handle(GetByChapterRequest request, CancellationToken cancellationToken)
        {
            var suggestions = await _aiSuggestionRepository.GetByChapterIdAsync(request.ChapterId, cancellationToken);
            return new GetByChapterResponse(suggestions);
        }
    }
}
