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

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

        /// <summary>
        /// 查询分类（含IVR）
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<IReadOnlyList<IvrCategory>> QueryCascadeAsync(CancellationToken cancellationToken = default)
        {
            return await Db.Queryable<IvrCategory>()
                .Includes(d => d.Ivrs)
                .ToListAsync();
        }

        /// <summary>
        /// 查询某个分类（含IVR）
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<IvrCategory> GetCascadeAsync(string id, CancellationToken cancellationToken = default)
        {
            return await Db.Queryable<IvrCategory>()
                .Includes(d => d.Ivrs)
                .Where(d => d.Ivrs.Any())
                .FirstAsync(d => d.Id == id);
        }
    }
}
