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

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

namespace BookingService.API.Application.Queries;

public class GetStaffScheduleQueryHandler : IRequestHandler<GetStaffScheduleQuery, List<StaffScheduleDto>>
{
    private readonly IStaffScheduleRepository _staffScheduleRepository;

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

    public async Task<List<StaffScheduleDto>> Handle(GetStaffScheduleQuery request, CancellationToken cancellationToken)
    {
        var schedules = await _staffScheduleRepository.GetByStaffIdAsync(request.StaffId, 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();
    }
}
