using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RestSharp;
using Common;

namespace WebSite.Models
{
    public class SendMQTTData
    {
        private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(SendMQTTData));
        public static void Send(IOTMonitorData t)
        {
            try
            {
                //string debug_log_report_url = RCUHost.TimingHelper.Common.debug_log_report_url;
                ////这个是 定阅的服务器要写的
                //string debug_log_report_mqtt_topic = "blw/iot/monitor/";

                string str = Newtonsoft.Json.JsonConvert.SerializeObject(t);
                //var client1 = new RestClient(debug_log_report_url);
                //var request1 = new RestRequest("/", Method.POST);

                ////注意方法是POST
                ////两个参数名字必须是 topic 和payload ，区分大小写的
                //request1.AddParameter("topic", debug_log_report_mqtt_topic);
                //request1.AddParameter("payload", str);


                //client1.ExecuteAsync(request1, (response) => { });

                CSRedisCacheHelper.redis3.Publish("redis-iotpackage", str);
            }
            catch (Exception ex)
            {
                logger.Error("SendMQTTData: " + ex.Message);
            }
        }

        public static void WebAPI_DataSend<T>(T t, string topic)
        {
            try
            {
                string debug_log_report_url = RCUHost.TimingHelper.Common.debug_log_report_url;
                //这个是 定阅的服务器要写的
                //string debug_log_report_mqtt_topic = "blw/webapi/monitor/";

                string str = Newtonsoft.Json.JsonConvert.SerializeObject(t);
                var client1 = new RestClient(debug_log_report_url);
                var request1 = new RestRequest("/", Method.POST);

                //注意方法是POST
                //两个参数名字必须是 topic 和payload ，区分大小写的
                request1.AddParameter("topic", topic);
                request1.AddParameter("payload", str);


                client1.ExecuteAsync(request1, (response) => { });
            }
            catch (Exception ex)
            {
                logger.Error("SendMQTTData: " + ex.Message);
            }
        }
    }
    public class WebAPIMonitorData
    {
        public string RemoteIP { get; set; }
        public string HotelCode { get; set; }
        public string RoomNumber { get; set; }
        public string InvokStart_Time { get; set; }
        public string InvokEnd_Time { get; set; }
        public List<string> Parameters { get; set; }
        public string MethodName { get; set; }
    }
    public class IotDeviceData
    {
        public string DeviceName { get; set; }
        public string DeviceAddress { get; set; }
    }
    public class IOTMonitorData
    {
        public IOTMonitorData()
        {
            this.CreateTime = DateTime.Now;
        }
        /// <summary>
        /// /远程调用IP
        /// </summary>
        public string RemoteIP { get; set; }
        public string ControlClass { get; set; }

        public string SceneName { get; set; }
        public List<IotDeviceData> WhichOneDevice { get; set; }

        public double Step { get; set; }

        public string RequestId { get; set; }
        public string Platform { get; set; }

        public string TriggerTime { get; set; }

        public DateTime CreateTime { get; set; }

        public string HotelId { get; set; }
        public int HotelCode { get; set; }
        public string HotelName { get; set; }
        public string RoomNumber { get; set; }

        public string CommandDescription { get; set; }
    }
}