using APT.BaseData.Domain.Entities;
using APT.Infrastructure.Core;
using APT.Utility;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;

namespace APT.PF.WebApiControllers.Api.PF
{

    /// <summary>
    /// 系统日志
    /// </summary>
    [Route("api/PF/PFMqttConfig")]
    public partial class MqttConfigController : AuthorizeApiController<T_PF_MQTT_CONFIG>
    {

        /// <param name="data">
        /// 判断是否链接
        /// </param>
        /// <returns></returns>
        [HttpPost, Route("FullUpdate")]
        public JsonActionResult<bool> FullUpdate([FromBody] T_PF_MQTT_CONFIG entity)
        {
            return base.SafeExecute(() =>
            {
                var configTheme = entity.Nav_MqttConfigTheme;
                entity.Nav_MqttConfigTheme = null;
                this.UnifiedCommit(() =>
                {
                    this.UpdateEntityNoCommit(entity);
                    if (configTheme != null && configTheme.Any())
                        this.BantchSaveEntityNoCommit(configTheme);
                });
                return true;
            });
        }

        /// <param name="data">
        /// 获取MQTT配置
        /// </param>
        /// <returns></returns>
        [HttpPost, Route("Redis")]
        public JsonActionResult<IEnumerable<T_PF_MQTT_CONFIG>> Redis([FromBody] BaseFilter filter)
        {
            return base.SafeExecute<IEnumerable<T_PF_MQTT_CONFIG>>(() =>
            {
                List<T_PF_MQTT_CONFIG> retList = new List<T_PF_MQTT_CONFIG>();
                return this.GetEntitiesByRedis<T_PF_MQTT_CONFIG>(i => true, filter,"", "Nav_MqttConfigTheme");
            });
        }



    }
}
