using ConfigurationApi.IRepositories;
using MadRunFabric.Common;
using MadRunFabric.Common.Options;
using MadRunFabric.Model;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace ConfigurationApi.Repositories
{
    public class Sys_AppModule_InfoRepository : BaseRepository<Sys_AppModule_Info, string>, ISys_AppModule_InfoRepository
    {

        protected readonly IMongoCollection<Sys_AppModule_Info> m_collection;
        protected readonly ILogger<BaseRepository<Sys_AppModule_Info, string>> _logger;
        public Sys_AppModule_InfoRepository(IOptions<MongodbOptions> settings, ILogger<BaseRepository<Sys_AppModule_Info, string>> logger) : base(settings, logger)
        {
            m_collection = _collection;
            _logger = logger;
        }

        /// <summary>
        /// 根据菜单di禁用对应的数据（本质是更新，保证数据被更改可排查）
        /// </summary>
        /// <returns></returns>
        public async Task<bool> DelModule(string[] ids)
        {
            try
            {
                var imodel = new Sys_AppModule_Info();
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("state_flag", "2");
                var list = new List<FilterDefinition<Sys_AppModule_Info>>();
                var filterBuilder = Builders<Sys_AppModule_Info>.Filter;
                list.Add(filterBuilder.In("id", ids));
                var filter = Builders<Sys_AppModule_Info>.Filter.And(list);
                return await UpdateManay(imodel, dic, filter);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
                return false;
            }
        }

    }
}
