// EN: Handler for GetSchedulesByShopQuery.
// VI: Handler cho GetSchedulesByShopQuery.

using BookingService.API.Application.DTOs;
using BookingService.Infrastructure.Repositories;
using MediatR;

namespace BookingService.API.Application.Queries;

public class GetSchedulesByShopQueryHandler : IRequestHandler<GetSchedulesByShopQuery, List<StaffScheduleDto>>
{
    private readonly IStaffScheduleRepository _staffScheduleRepository;

    public GetSchedulesByShopQueryHandler(IStaffScheduleRepository staffScheduleRepository)
    {
        _staffScheduleRepository = staffScheduleRepository ?? throw new ArgumentNullException(nameof(staffScheduleRepository));
    }

    public async Task<List<StaffScheduleDto>> Handle(GetSchedulesByShopQuery request, CancellationToken cancellationToken)
    {
        var schedules = await _staffScheduleRepository.GetByShopIdAsync(request.ShopId, cancellationToken);

        return schedules.Select(s => new StaffScheduleDto
        {
            Id = s.Id,
            StaffId = s.StaffId,
            ShopId = s.ShopId,
            DayOfWeek = s.DayOfWeek,
            StartTime = s.StartTime,
            EndTime = s.EndTime
        }).ToList();
    }
}
