using System;
using System.Collections.Generic;

namespace SGModule.MarkdownKit {
    public class MarkdownData {
        public int BaseSize;
        public List<string> MarkdownTextList;
        public Action<bool, List<string>> OnComplete;
        public List<string> RichTextList;
        public MarkdownTextState State;
        public string Text;
        public string Url;
    }

    public enum MarkdownTextState {
        None,
        Downloading,
        Complete,
        Exception
    }

    public static class MarkdownDataMgr {
        private static readonly Dictionary<string, MarkdownData> _markdownData = new();

        /// <summary>
        ///     获取完整数据
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static MarkdownData GetData(string key) {
            return _markdownData.GetValueOrDefault(key);
        }

        /// <summary>
        ///     获取当前状态
        /// </summary>
        /// <param name="key">自定义的键名</param>
        /// <returns></returns>
        public static MarkdownTextState GetState(string key) {
            var data = GetData(key);
            if (data != null) {
                return data.State;
            }

            return MarkdownTextState.None;
        }

        /// <summary>
        ///     获取当前状态
        /// </summary>
        /// <param name="key">自定义的键名</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static bool TryAdd(string key, MarkdownData data) {
            return _markdownData.TryAdd(key, data);
        }

        /// <summary>
        ///     获取当前状态
        /// </summary>
        /// <param name="key">自定义的键名</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public static bool TryGetValue(string key, out MarkdownData data) {
            return _markdownData.TryGetValue(key, out data);
        }
    }
}
