using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using static PortQuery;

/// <summary>
/// 环境-查询
/// </summary>
[AddComponentMenu("环境查询")]
public class ENVQuery : MonoBehaviour
{
    public ENVList eNVList;

    private async void Start()
    {
        //await initAsync("");
    }

    public async Task initAsync(string token)
    {
        var jsonResult = await CombineJSON.GetJson_POST("https://jsonplaceholder.typicode.com/posts", token);

        Root root = JsonConvert.DeserializeObject<Root>(jsonResult);

        foreach (var item in root.data)
        {
            if (item.pointId == eNVList.pointId)
            {
                eNVList = item;
                break;
            }
        }
    }

    void Update()
    {

    }

    #region JSON
    public class ENVList
    {
        /// <summary>
        /// 点位ID
        /// </summary>
        [Tooltip("点位ID")] public int pointId;
        /// <summary>
        /// 点位设备ID
        /// </summary>
        [Tooltip("点位设备ID")] public int pointDeviceId;
        /// <summary>
        /// 点位名称
        /// </summary>
        [Tooltip("点位名称")] public string pointName;
        /// <summary>
        /// 点位类型：1-温度；2-湿度；3-烟感；4-水浸
        /// </summary>
        [Tooltip("点位类型：1-温度；2-湿度；3-烟感；4-水浸")] public string pointType;
        /// <summary>
        /// 点位状态
        /// </summary>
        [Tooltip("点位状态")] public string pointStatus;
        /// <summary>
        /// 采集时间
        /// </summary>
        [Tooltip("采集时间")] public int collectDate;
        /// <summary>
        /// 当前状态(采集结果)
        /// </summary>
        [Tooltip("当前状态(采集结果)")] public string collectResult;
    }

    public class Root
    {
        /// <summary>
        /// 
        /// </summary>
        public string code;
        /// <summary>
        /// 操作成功
        /// </summary>
        public string message;
        /// <summary>
        /// 
        /// </summary>
        public List<ENVList> data;
        /// <summary>
        /// 
        /// </summary>
        public string serverTime;
    }

    #endregion
}
