using Hotline.CallCenter.Tels;
using Hotline.Repository.SqlSugar.DataPermissions;
using SqlSugar;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.CallCenter
{
    public class TelRestRepository : BaseRepository<TelRest>, ITelRestRepository, IScopeDependency
    {
        public TelRestRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
        {
        }

        /// <summary>
        /// 分机是否正在休息
        /// </summary>
        /// <param name="telNo"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<bool> IsRestingAsync(string telNo, CancellationToken cancellationToken)
        {
            return Db.Queryable<TelRest>().AnyAsync(d => d.TelNo == telNo && !d.EndTime.HasValue);
        }

        /// <summary>
        /// 分机休息是否在审核阶段
        /// </summary>
        /// <param name="telNo"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<bool> IsApplyingAsync(string telNo, CancellationToken cancellationToken)
        {
            return Db.Queryable<TelRest>().AnyAsync(d => d.TelNo == telNo && !d.EndTime.HasValue && !d.StartTime.HasValue && d.ApplyStatus == Share.Enums.CallCenter.ETelRestApplyStatus.NoAudit);
        }
    }
}
