using BeetleX.BNR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;

namespace IRaCIS.Application.Services
{
    [ApiExplorerSettings(GroupName = "Institution")]
    public class TestService : BaseService
    {
        private readonly IRepository<Dictionary> _dicRepository;
        private readonly IRepository<Trial> _trialRepository;

        //private readonly IDistributedCache _cache;

        public TestService(IRepository<Dictionary> dicRepository, IRepository<Trial> trialRepository/*, IDistributedCache cache*/)
        {
            _dicRepository = dicRepository;
            _trialRepository = trialRepository;
            //_cache = cache;
        }

        public async Task<string>  Get()
        {

            //var subject1 = Guid.Parse("431D0C58-ABC5-4166-B9BC-08DA0E391693");
            //var subject2 = Guid.Parse("431D0C58-ABC5-4166-B9BC-08DA0E391694");

            //    var subjectList = new List<Guid>() { Guid.Parse("431D0C58-ABC5-4166-B9BC-08DA0E391693") ,
            //                                      Guid.Parse("431D0C58-ABC5-4166-B9BC-08DA0E391694") ,
            //                                       Guid.Parse("431D0C58-ABC5-4166-B9BC-08DA0E391695")
            //    };

            //string[] citys = new string[] { "广州", "深圳", "上海", "北京" };
            //foreach (var item in subjectList)
            //{
            //    Console.WriteLine(await BNRFactory.Default.Create($"[CN:{item}][N:[CN:{item}]/0000000]"));
            //}
            //foreach (var item in subjectList)
            //{
            //    Console.WriteLine(await BNRFactory.Default.Create($"[N:[CN:{item}]/0000000]"));
            //}

            //foreach (var item in subjectList)
            //{
            //    Console.WriteLine(await BNRFactory.Default.Create($"[CN:{item}][redis:city/0000000]"));
            //}

            var needAddVisitList = await _repository.Where<VisitTask>(t => t.TrialId == Guid.Empty).DistinctBy(t => t.VisitTaskNum).ToListAsync();

            return _userInfo.LocalIp;
        }

        [HttpPost]
        public string Get(TestModel testModel)
        {

            //_cache.SetString("test" , "cacheStr");

            //var aa=  _trialRepository.Where(t => t.Id == Guid.Empty).First();

            //var aaabb = _trialRepository.BatchDeleteNoTrackingAsync(t => t.Id == Guid.Empty).Result;

            //var aaaa = _dicRepository.BatchDeleteNoTrackingAsync(t => t.Id == Guid.Empty).Result;


            //var waitModifyEntity = _dicRepository.FirstOrDefaultAsync(t => t.Id == Guid.Parse("e2b97a6c-35a6-4aa3-7f27-08da13ab33ff")).GetAwaiter().GetResult();

            //var tt = _dicRepository.UpdateAsync(waitModifyEntity, t => new Dictionary() { Description = "xxxxx" }, true).Result;



            //var tt2 = _trialRepository.UpdatePartialFromQueryAsync(Guid.Parse("543d0000-3e10-0016-77e9-08da2827228a"), t => new Trial() { Indication = "WCH测试稽查002" }, true).Result;




            //var d = _repository.Where<User>(t => t.FullName.Contains("cc")).Select(t => t.FullName).FirstOrDefault();
            //var c = _dicRepository.Where(t => t.ParentId != null).Select(t => t.MappedValue).First();
            //CultureInfo culture = CultureInfo.CurrentUICulture;

            //var dd = _dicRepository.UpdatePartialFields(Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),
            //        u => new Dictionary() { ParentId = null, Code = "test" }, true);


            //var ggggg = _dicRepository.UpdateFromQueryAsync(t => t.ParentId == Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"), u=>new Dictionary(){Code = "test"}).Result;

            //var ddd = _dicRepository.BatchUpdateAsync(t => t.Id == Guid.Parse("8a90c96e-0776-4f7b-82a6-18933d339584"),
            //   u => new Dictionary() { /*ParentId = null,*/ Code = "test" }).Result;


            //var  aaaaa= _trialRepository.BatchUpdateAsync(t => t.Id == Guid.Empty,
            //    u => new SubjectVisit() { CurrentActionUserId = null }).Result;


            //var d = _dicRepository.UpdateFromDTOAsync(new AddOrEditBasicDic() { Id = Guid.Parse("60d86683-c33b-4349-b672-08da1e91b622"), ParentId = null, ChildGroup = null, Code = null }, true, true).Result;
            var a = 123;

            var b = _localizer["test{0}", "测试"];
            //return _localizer["test{0}", "测试"];


            //var list = _repository.Where<SubjectVisit>(t => t.Id == Guid.NewGuid()).SelectMany(t => t.VisitTaskList).ToList();

            //var list2 = _repository.Where<VisitTask>(t => t.Id == Guid.NewGuid()).Select(t => t.SourceSubjectVisit).ToList();

            //var list3 = _repository.Where<VisitTask>(t => t.Id == Guid.NewGuid()).SelectMany(t => t.SourceSubjectVisit.VisitTaskList).ToList();
            var list2 = _repository.Where<Subject>(t => t.Id == Guid.NewGuid()).SelectMany(t => t.SubjectVisitTaskList).ToList();
            return _userInfo.LocalIp;
        }



        public string PostData(List<TestModel> testModelList)
        {
            return string.Join(",", testModelList);
        }
    }

    public class TestModel
    {

        //[Required]
        public string Id { get; set; }

        public string Name { get; set; }
    }
}


namespace Localization
{
    public class SharedResource
    {
    }
}