package org.springblade.plugin.workflow.chat.core.cache;

import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.tool.utils.SpringUtil;
import org.springblade.plugin.workflow.chat.pojo.entity.WfChatAppEntity;
import org.springblade.plugin.workflow.chat.service.IWfChatAppService;

public class WfChatCache {

	private static final String CHAT_CACHE = "wf:chat:";
	private static final String CHAT_APP_ID = "app:id:";

	private static final IWfChatAppService chatAppService;

	static {
		chatAppService = SpringUtil.getBean(IWfChatAppService.class);
	}

	public static WfChatAppEntity getChatApp(Long id) {
		return CacheUtil.get(CHAT_CACHE, CHAT_APP_ID, id, () -> chatAppService.getById(id));
	}

	public static void clearCache() {
		CacheUtil.clear(CHAT_CACHE);
		CacheUtil.clear(CHAT_CACHE, false);
	}

}
