using System;
using System.Collections.Generic;

namespace SGModule.DataStorage {
    /// <summary>
    ///     数据键的抽象类，提供键名的统一管理。
    /// </summary>
    public class DataKeyInfo {
        public DataKeyInfo(Type type, bool cloudSave = true) {
            Type = type;
            CloudSave = cloudSave;
        }

        /// <summary>
        /// 数据类型
        /// </summary>
        public Type Type {
            get;
        }

        /// <summary>
        /// 是否需要云端保存
        /// </summary>
        public bool CloudSave {
            get;
        }
    }

    public static class DataKeyDic {
        private static readonly Dictionary<string, DataKeyInfo> _keyDic = new();

        public static bool Register<T>(string key, bool cloudSave = true) {
            if (_keyDic.ContainsKey(key)) {
                return false;
            }

            _keyDic.Add(key, new DataKeyInfo(typeof(T), cloudSave));
            return true;
        }

        public static DataKeyInfo Get(string keyName) {
            return _keyDic.GetValueOrDefault(keyName);
        }
    }
}
