using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AudioWallpaper.Entity {
    [Serializable]
    public class OtherConfigObjects {
        /// <summary>
        /// 配置名称
        /// </summary>
        private const string CONFIG_NAME = "OtherConfig";

        /// <summary>
        /// 是否使用陪伴助手
        /// </summary>
        public bool UseAccompanyingAssistant = false;

        /// <summary>
        /// Bucket名称
        /// </summary>
        public string? BucketName = null;
        /// <summary>
        /// 数据获取范围时间
        /// </summary>
        public string? RangeTime = null;
        /// <summary>
        /// 数据获取间隔时间，单位秒，默认五分钟
        /// </summary>
        public int Interval = 60 * 5;

        public string DisplayName = "Unknown";

        /// <summary>
        /// 该配置是否为全局配置
        /// </summary>
        private const bool OVERALL_SITUATION = true;


        public bool SaveConfig(string configFilePath) {
            ConfigurationTools configurationTools = new ConfigurationTools(configFilePath);

            string fullConfigName = OVERALL_SITUATION ? CONFIG_NAME : DisplayName + "_" + CONFIG_NAME;

            configurationTools.AddSetting(fullConfigName, "UseAccompanyingAssistant", UseAccompanyingAssistant.ToString());
            configurationTools.AddSetting(fullConfigName, "BucketName", BucketName ?? string.Empty);
            configurationTools.AddSetting(fullConfigName, "RangeTime", RangeTime ?? string.Empty);
            configurationTools.AddSetting(fullConfigName, "Interval", Interval.ToString());

            configurationTools.SaveSettings();
            return true;
        }
        public OtherConfigObjects LoadConfig(string configFilePath, string name) {
            try {
                ConfigurationTools configurationTools = new ConfigurationTools(configFilePath);
                string fullConfigName = OVERALL_SITUATION ? CONFIG_NAME : name + "_" + CONFIG_NAME;
                UseAccompanyingAssistant = Convert.ToBoolean(configurationTools.GetSetting(fullConfigName, "UseAccompanyingAssistant"));
                BucketName = configurationTools.GetSetting(fullConfigName, "BucketName");
                RangeTime = configurationTools.GetSetting(fullConfigName, "RangeTime");
                Interval = Convert.ToInt32(configurationTools.GetSetting(fullConfigName, "Interval"));
                return this;
            } catch (Exception) {
                return this;
            }
        }
    }
}
