using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;

namespace FLY.FilmCasting.AutoDie.Common
{
    public class ChannelValuesMark
    {
        public string name;
        public int[] channelValues;
    }

    public class ChannelValuesMarkJsonDb
    {
        /// <summary>
        /// 当前正在使用的产品参数
        /// </summary>
        public string CurrMarkName { get; set; }
        /// <summary>
        /// 参数列表！！！！！
        /// </summary>
        public List<ChannelValuesMark> Marks { get; set; } = new List<ChannelValuesMark>();

        public ChannelValuesMarkJsonDb()
        {
            Load();
        }
        string file_path = "marks.json";
        void Load()
        {
            try
            {
                if (File.Exists(file_path))
                {
                    string json = File.ReadAllText(file_path);
                    JsonConvert.PopulateObject(json, this);
                    if (Marks == null)
                        Marks = new List<ChannelValuesMark>();
                    return;
                }
            }
            catch
            {
                //异常，没有json 解码失败

            }
        }

        public bool Save()
        {
            try
            {
                File.WriteAllText(file_path, JsonConvert.SerializeObject(this, Formatting.Indented));
                return true;
            }
            catch
            {
                //异常，没有json 编码失败

            }
            return false;
        }
    }
}
