using System.ComponentModel;
using System.Linq.Expressions;
using Exam.Repository.Sqlsugar.Validators.Sourcewares;
using Hotline.Exams.Sourcewares;
using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Repository.SqlSugar.Exam.Extensions;
using Hotline.Repository.SqlSugar.Exam.Interfaces.Sourcewares;
using SqlSugar;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.Exam.Repositories.Sourcewares
{
    /// <summary>
    /// 课件类型仓储
    /// </summary>
    [Description("课件类型仓储")]
    public class SourcewareCategoryRepository : ExamRepository<ExamSourcewareCategory>, ISourcewareCategoryRepository, IScopeDependency
    {
        public SourcewareCategoryRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
        {
            Validator = new SourcewareCategoryValidator(this,dataPermissionFilterBuilder,serviceProvider);
        }

        /// <summary>
        /// 获取树形接口
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public async Task<List<ExamSourcewareCategory>> GetTreeAsync(Expression<Func<ExamSourcewareCategory, bool>> expression)
        {
            var sourcewareCategoryList = await this.GetTree(expression).OrderBy(o => o.SortIndex).ToTreeAsync(m => m.Children, p => p.ParentId, "");

            return sourcewareCategoryList;
        }
    }
}

