using System;
using System.Collections.Generic;
using DefaultNamespace.Dto;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;

namespace ToolsPack
{
    public class ElectricEnergyMeterData : MonoBehaviour
    {
        public List<string> valueNumber = new List<string>();
        public TMP_Text te;

        private void Start()
        {
            string json = @"
        {
            'scenename': '场景名称',
            'questbooks': '本次训练任务默认停电作业，现场集中器损坏，需要查看情况，并处理。',
            'userinformation': '用户基本信息',
            'energyinformation': '现场电能表信息内容',
            'energylist': [
                {
                    'work': '正向有功',
                    'worklist': [
                        {'keywork': '总', 'valuework': '630732.86'},
                        {'keywork': '尖', 'valuework': '0'},
                        {'keywork': '峰', 'valuework': '600227.02'},
                        {'keywork': '平', 'valuework': '0'},
                        {'keywork': '谷', 'valuework': '30505.84'}
                    ]
                },
                {
                    'work': '正向无功',
                    'worklist': [
                        {'keywork': '总', 'valuework': '90704.72'},
                        {'keywork': '尖', 'valuework': '0'},
                        {'keywork': '峰', 'valuework': '82394.39'},
                        {'keywork': '平', 'valuework': '0'},
                        {'keywork': '谷', 'valuework': '8310.33'}
                    ]
                },
                {
                    'work': '反向有功',
                    'worklist': [
                        {'keywork': '总', 'valuework': '0'},
                        {'keywork': '尖', 'valuework': '0'},
                        {'keywork': '峰', 'valuework': '0'},
                        {'keywork': '平', 'valuework': '0'},
                        {'keywork': '谷', 'valuework': '0'}
                    ]
                },
                {
                    'work': '反向无功',
                    'worklist': [
                        {'keywork': '总', 'valuework': '18385.2'},
                        {'keywork': '尖', 'valuework': '0'},
                        {'keywork': '峰', 'valuework': '13222.55'},
                        {'keywork': '平', 'valuework': '0'},
                        {'keywork': '谷', 'valuework': '5162.65'}
                    ]
                }
            ]
        }";

            // 解析JSON字符串
            // ElectricEnergyData electricEnergyData = JsonConvert.DeserializeObject<ElectricEnergyData>(json);

            // // 输出一些数据来验证解析
            // Debug.Log("场景名称: " + sceneData.scenename);
            // Debug.Log("任务描述: " + sceneData.questbooks);
            // Debug.Log("用户信息: " + sceneData.userinformation);
            // Debug.Log("电能表信息: " + sceneData.energyinformation);
            //
            // foreach (var energy in electricEnergyData.energylist)
            // {
            //     // Debug.Log("Work: " + energy.work);
            //     foreach (var worklist in energy.worklist)
            //     {
            //         valueNumber.Add(worklist.valuework);
            //         // Debug.Log($"Key: {worklist.keywork}, Value: {worklist.valuework}");
            //     }
            // }
        }

        public void SetValue(int index)
        {
            te.text = valueNumber[index];
        }
    }
}