using Hotline.Repository.SqlSugar.DataPermissions;
using Hotline.Settings;
using Hotline.Share.Enums.Settings;
using SqlSugar;
using XF.Domain.Dependency;

namespace Hotline.Repository.SqlSugar.System
{
    public class SystemDataAuthorityRepository : BaseRepository<SystemDataAuthority>, ISystemDataAuthorityRepository, IScopeDependency
    {
        public SystemDataAuthorityRepository(ISugarUnitOfWork<HotlineDbContext> uow, IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider) : base(uow, dataPermissionFilterBuilder, serviceProvider)
        {
        }

        public ETableAccessLevel GetMyTopDataAuth(string[] roles,string tableid)
        {
            var dataAuth =Db.Queryable<SystemDataAuthority>().Where(x => roles.Contains(x.RoleCode) && x.TableId == tableid).Min(x=>x.AuthorityType);
            return dataAuth;
        }
    }
}
