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

/// <summary>
/// 板卡-查询
/// </summary>
[AddComponentMenu("板卡查询"), Serializable]
public class TmsCardQuery : MonoBehaviour
{

    public TmsCardList tmsCardList;

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


    #region JSON
    [Serializable]
    public class TmsCardList
    {
        /// <summary>
        /// 主键id
        /// </summary>
        [Tooltip("")] public string cardId;
        /// <summary>
        /// 名称
        /// </summary>
        [Tooltip("名称")] public string deviceName;
        /// <summary>
        /// 端口数量
        /// </summary>
        [Tooltip("端口数量")] public int portNum;
        /// <summary>
        /// 所在机槽Id
        /// </summary>
        [Tooltip("所在机槽Id")] public string slotId;
        /// <summary>
        /// 所在机槽名称
        /// </summary>
        [Tooltip("所在机槽名称")] public string slotName;
        /// <summary>
        /// 板卡类型
        /// </summary>
        [Tooltip("板卡类型")] public string cardType;
        /// <summary>
        /// 板卡型号
        /// </summary>
        [Tooltip("板卡型号")] public string cardModel;
        /// <summary>
        /// 生产厂家
        /// </summary>
        [Tooltip("")] public string manufacturer;
        /// <summary>
        /// 投运时间
        /// </summary>
        [Tooltip("")] public int operationTime;
        /// <summary>
        /// 运行状态
        /// </summary>
        [Tooltip("")] public string runStatus;
    }

    [Serializable]
    public class Root
    {
        /// <summary>
        /// 
        /// </summary>
        public string code;
        /// <summary>
        /// 操作成功
        /// </summary>
        public string message;
        /// <summary>
        /// 
        /// </summary>
        public List<TmsCardList> data;
        /// <summary>
        /// 
        /// </summary>
        public string serverTime;
    }
    #endregion
}
