using XF.Domain.Dependency;
using XF.Domain.Exceptions;
using XF.Domain.Repository;

namespace Hotline.Settings.CommonOpinions
{
    public class SystemCommonOpinionDomainService : ISystemCommonOpinionDomainService, IScopeDependency
    {
        private readonly IRepository<SystemCommonOpinion> _commonOpinionRepository;

        public SystemCommonOpinionDomainService(IRepository<SystemCommonOpinion> commonOpinionRepository)
        {
            _commonOpinionRepository = commonOpinionRepository;
        }
        public async Task AddCommonOpinion(SystemCommonOpinion entity, CancellationToken cancellationToken)
        {
            await _commonOpinionRepository.AddAsync(entity, cancellationToken);
        }

      

        public async Task DelCommonOpinion(string[] Ids, CancellationToken cancellationToken)
        {
            //TODO 加权限
            var list = await _commonOpinionRepository.Queryable().In(Ids).ToListAsync();
            if (list.Count != Ids.Length)
            {
                throw new UserFriendlyException("数据异常，无权限操作");
            }
            await _commonOpinionRepository.RemoveRangeAsync(list, cancellationToken);
        }
    }
}
