using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json;

namespace AI.Platform.Page.Pages.Media
{
    public class Utils
    {
        private static Dictionary<string, string> _StateDic = new Dictionary<string, string>()
        {
            { "idle","空闲" },{ "lock","锁枪" },{ "offline","脱机" },{ "lift","提枪" },{ "authorised","授权" },{ "start","开始" },{ "fueling","加油中" }
        };

        /// <summary>
        /// 根据数据库中的油枪状态json转中文拼接
        /// </summary>
        /// <param name="jsonStr"></param>
        /// <returns></returns>
        public static string MachineStateJsonToString(string jsonStr)
        {
            List<string>? list = JsonSerializer.Deserialize<List<string>>(jsonStr);
            if (list == null || list.Count == 0) return "";

            var result = "";
            foreach(string item in list)
            {
                string? state = _StateDic.GetValueOrDefault(item);
                if (state == null || state.Length == 0) continue;
                 result += state + "，";
            }
            return result.Remove(result.Length - 1);
        }

        public static string JoinDateTime(DateTime start,DateTime end)
        {
            return $"{start}-{end}";
        }
    }
}
