/*
 *  Copyright 2025-2026 R3944Realms
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package top.r3944realms.eroticdungeongame.content.block;

/**
 * 形状缓存接口
 * 提供形状缓存管理功能
 * @param <M> 形状映射
 */
public interface IShapeCache<M> {
    Object SINGLE = new Object();
    /**
     * 初始化形状缓存
     */
    void initCache();

    /**
     * 获取形状映射
     * @return 方向到形状的映射
     */
    default M getShapeCacheMap() {
        return getShapeCacheMap(SINGLE);
    }

    /**
     * 获取形状映射
     * @param key 键
     * @return 方向到形状的映射
     */
     M getShapeCacheMap(Object key);

    /**
     * 设置形状映射
     * @param shapeMap 方向到形状的映射
     */
    void setShapeCacheMap(M shapeMap);

    /**
     * 重新加载形状缓存
     */
    void reloadShapesCache();

    /**
     * 清理缓存
     */
    default void clearCache() {
        setShapeCacheMap(null);
    }

    /**
     * 检查缓存是否已初始化
     * @return 是否已初始化
     */
    default boolean isCacheInitialized() {
        return isCacheInitialized(SINGLE);
    }

    /**
     * 检查对应key下的缓存是否已初始化
     * @param key 键
     * @return 是否已初始化
     */
    default boolean isCacheInitialized(Object key) {
        return getShapeCacheMap(key) != null;
    }
}
