// EN: Repository implementation for StaffSchedule.
// VI: Implementation repository cho StaffSchedule.

using BookingService.Domain.AggregatesModel.StaffAggregate;
using BookingService.Domain.SeedWork;
using Microsoft.EntityFrameworkCore;

namespace BookingService.Infrastructure.Repositories;

public class StaffScheduleRepository : IStaffScheduleRepository
{
    private readonly BookingContext _context;

    public IUnitOfWork UnitOfWork => _context;

    public StaffScheduleRepository(BookingContext context)
    {
        _context = context ?? throw new ArgumentNullException(nameof(context));
    }

    public StaffSchedule Add(StaffSchedule schedule)
    {
        return _context.StaffSchedules.Add(schedule).Entity;
    }

    public void Update(StaffSchedule schedule)
    {
        _context.Entry(schedule).State = EntityState.Modified;
    }

    public void Remove(StaffSchedule schedule)
    {
        _context.StaffSchedules.Remove(schedule);
    }

    public async Task<List<StaffSchedule>> GetByStaffIdAsync(Guid staffId, Guid shopId, CancellationToken cancellationToken = default)
    {
        return await _context.StaffSchedules
            .Where(s => s.StaffId == staffId && s.ShopId == shopId)
            .ToListAsync(cancellationToken);
    }

    public async Task<List<StaffSchedule>> GetByShopIdAndDayAsync(Guid shopId, int dayOfWeek, CancellationToken cancellationToken = default)
    {
        return await _context.StaffSchedules
            .Where(s => s.ShopId == shopId && s.DayOfWeek == dayOfWeek)
            .ToListAsync(cancellationToken);
    }
}
