package com.qingyun.service.agent;

import cn.hutool.core.io.resource.ResourceUtil;

import java.io.BufferedReader;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

public class TemplateManager {
    private static final Map<String, String> TEMPLATE_CACHE = new HashMap<>();

    public static String getTemplate(String templateKey) {
        return TEMPLATE_CACHE.computeIfAbsent(templateKey, k -> {
            BufferedReader reader = ResourceUtil.getReader(k, Charset.defaultCharset());
            try {
                return ResourceReadUtils.convert(reader);
            } catch (Exception e) {
                throw new RuntimeException("加载模板文件失败: " + k, e);
            }
        });
    }
}
