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

/// <summary>
/// 端口-查询
/// </summary>
[AddComponentMenu("端口查询")]
public class PortQuery : MonoBehaviour
{

    public PortList portList;



    private void Awake()
    {

    }

    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.id == portList.id)
            {
                portList = item;
                break;
            }
        }
    }


    /// <summary>
    /// 更新端口JSON
    /// </summary>
    /// <returns></returns>
    string refreshJson()
    {

        string json = JsonConvert.SerializeObject(portList);
        //Debug.Log(json);
        return json;
    }

    #region JSON
    [System.Serializable]
    public class PortList
    {
        /// <summary>
        /// id
        /// </summary>
        [Tooltip("")] public string id;
        /// <summary>
        /// 端口
        /// </summary>
        [Tooltip("端口")] public string port;
        /// <summary>
        /// 编号
        /// </summary>
        [Tooltip("编号")] public string portCode;
        /// <summary>
        /// 名称
        /// </summary>
        [Tooltip("名称")] public string portName;
        /// <summary>
        /// 端口类型
        /// </summary>
        [Tooltip("端口类型")] public string portType;
        /// <summary>
        /// 所属设备
        /// </summary>
        [Tooltip("所属设备")] public string deviceId;
        /// <summary>
        /// 端口型号
        /// </summary>
        [Tooltip("端口型号")] public string portModel;
        /// <summary>
        /// 是否启用：1-正常；0-禁用
        /// </summary>
        [Tooltip("是否启用：1-正常；0-禁用")] public int status;
        /// <summary>
        /// 对联设备
        /// </summary>
        [Tooltip("对联设备")] public string conDevice;
        /// <summary>
        /// 对联端口
        /// </summary>
        [Tooltip("对联端口")] public string conPort;
        /// <summary>
        /// 备注
        /// </summary>
        [Tooltip("备注")] public string remark;
        /// <summary>
        /// 
        /// </summary>
        [Tooltip("")] public int createTime;
        /// <summary>
        /// 
        /// </summary>
        [Tooltip("")] public string createName;
    }


    [System.Serializable]
    public class Root
    {
        /// <summary>
        /// 
        /// </summary>
        public string code;
        /// <summary>
        /// 操作成功
        /// </summary>
        public string message;
        /// <summary>
        /// 
        /// </summary>
        public string totalRows;
        /// <summary>
        /// 
        /// </summary>
        public int pageSize;
        /// <summary>
        /// 
        /// </summary>
        public int pageNum;
        /// <summary>
        /// 
        /// </summary>
        public List<PortList> data;
    }
    #endregion
}
