using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Users;
using SqlSugar;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.CallCenter;

public class WorkRepository : BaseRepository<Work>, IWorkRepository, IScopeDependency
{
    public WorkRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
    {
    }

    public async Task<Work> GetCurrentWorkByUserAsync(string userId, CancellationToken cancellationToken = default)
        => await Db.Queryable<Work>().FirstAsync(d => d.UserId == userId && !d.EndTime.HasValue);

    public async Task<Work> GetCurrentWorkByTelAsync(string telNo, CancellationToken cancellationToken = default)
        => await Db.Queryable<Work>().FirstAsync(d => d.TelNo == telNo && !d.EndTime.HasValue);
}