using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using UnityEngine;
using static ENVQuery;

/// <summary>
/// 机柜-查询
/// </summary>
[AddComponentMenu("机柜查询"), Serializable]
public class CabinetQuery : MonoBehaviour
{
    public CabinetList cabinetList;

    private void Awake()
    {

    }


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

    public async Task initAsync(string token)
    {
        var jsonResult = await CombineJSON.GetJson_POST("http://wu4ifs.natappfree.cc/machineRoom/tmsRack/queryList", token);

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

        foreach (var item in root.data)
        {
            if (item.rackId == cabinetList.rackId)
            {
                cabinetList = item;
                break;
            }
        }
    }

    private void Update()
    {
        
    }

    #region JSON
    [Serializable]
    public class CabinetList
    {
        /// <summary>
        /// 主键id
        /// </summary>
        [Tooltip("")] public string rackId;
        /// <summary>
        /// 机柜名称
        /// </summary>
        [Tooltip("机柜名称")] public string deviceName;
        /// <summary>
        /// 机柜类型
        /// </summary>
        [Tooltip("机柜类型")] public string type;
        /// <summary>
        /// 生产厂家
        /// </summary>
        [Tooltip("生产厂家")] public string manufacturer;
        /// <summary>
        /// 投运时间
        /// </summary>
        [Tooltip("投运时间")] public int operationTime;
        /// <summary>
        /// 产权单位
        /// </summary>
        [Tooltip("产权单位")] public string rackPropertyUnit;
        /// <summary>
        /// 维护单位
        /// </summary>
        [Tooltip("维护单位")] public string maintenanceUnit;
        /// <summary>
        /// 负责人
        /// </summary>
        [Tooltip("负责人")] public string directorName;
        /// <summary>
        /// 手机号
        /// </summary>
        [Tooltip("手机号")] public string phone;
        /// <summary>
        /// 用途描述
        /// </summary>
        [Tooltip("用途描述")] public string rackUsageDescription;
        /// <summary>
        /// 颜色
        /// </summary>
        [Tooltip("颜色")] public string rackColor;
        /// <summary>
        /// 所属机房id
        /// </summary>
        [Tooltip("所属机房id")] public string roomId;
    }

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

}
