using System.Runtime.CompilerServices;
using static ZelWiki.Caching.WikiCache;

namespace ZelWiki.Caching
{
    public class WikiCacheKeyFunction(string key) : IWikiCacheKey
    {
        public string Key { get; set; } = key;

        /// <summary>
        /// 生成一个包含调用函数名称的缓存键。
        /// </summary>
        public static WikiCacheKeyFunction Build(WikiCache.Category category, object?[] segments, [CallerMemberName] string callingFunction = "")
            => new($"[{category}]:[{string.Join("]:[", segments)}]:[{callingFunction}]");

        /// <summary>
        /// 生成一个包含调用函数名称的缓存键。
        /// </summary>
        public static WikiCacheKeyFunction Build(WikiCache.Category category, [CallerMemberName] string callingFunction = "")
            => new($"[{category}]:[{callingFunction}]");
    }
}
