using EasyCaching.Core;
using IRaCIS.Core.Domain.Share;
using IRaCIS.Core.Infra.EFCore;
using MediatR;

namespace IRaCIS.Core.Application.MediatR.Handlers
{

    public class AnonymizeCacheRequest : IRequest<bool>
    {

    }
    public class AnonymizeCacheHandler : IRequestHandler<AnonymizeCacheRequest,bool>
    {     
        private readonly IRepository _repository;

        private readonly IEasyCachingProvider _provider;

        /// <summary>
        /// 构造函数注入
        /// </summary>
        public AnonymizeCacheHandler(IRepository repository, IEasyCachingProvider provider)
        {
            _repository = repository;

            _provider = provider;
        }

      
        public Task<bool> Handle(AnonymizeCacheRequest request, CancellationToken cancellationToken)
        {
            var systemAnonymizationList = _repository.Where<SystemAnonymization>(t => t.IsEnable).ToList();

            _provider.Set(StaticData.Anonymize.Anonymize_AddFixedFiled, systemAnonymizationList.Where(t => t.IsAdd && t.IsFixed).ToList(), TimeSpan.FromDays(7));
            _provider.Set(StaticData.Anonymize.Anonymize_AddIRCInfoFiled, systemAnonymizationList.Where(t => t.IsAdd && t.IsFixed == false).ToList(), TimeSpan.FromDays(7));
            _provider.Set(StaticData.Anonymize.Anonymize_FixedField, systemAnonymizationList.Where(t => t.IsAdd == false && t.IsFixed).ToList(), TimeSpan.FromDays(7));
            _provider.Set(StaticData.Anonymize.Anonymize_IRCInfoField, systemAnonymizationList.Where(t => t.IsAdd == false && t.IsFixed == false).ToList(), TimeSpan.FromDays(7));

            return Task.FromResult(true);
        }
    }


}
