import { useAuthStore } from "@/store/auth";
import { ChatMessage } from "../model/Message";
import { LocalMessageIdPool } from "./Messages";
import type { ChatConfig } from "./Chat";

export function useChatStaticMessages(config: ChatConfig) {
  const authStore = useAuthStore();

  const EMPTY_MESSAGE = ChatMessage.createEphemeralAssistant(
    '请输入您要提问的内容，让我知道您需要什么。',
    LocalMessageIdPool.getNextId()
  );

  return {
    getWelcomeMessage: () => {
      let message = '你好！欢迎使用梦鱼的智能助手。发送消息开始聊天。';
      let actions: string[] = [];
      if (config.onBuildWelcome) {
        const { welcomeMessage, welcomeActions } = config.onBuildWelcome();
        message = welcomeMessage ?? message;
        actions = welcomeActions ?? actions;
      } else {
        if (authStore.userInfo?.name) {
          if (authStore.userInfo?.id === 1)
            message = `尊敬的梦鱼可爱小主，欢迎😀 智能助手为您服务。可以问我任何问题。`;
          else
            message = `你好！${authStore.userInfo?.name}，欢迎使用梦鱼的智能助手。发送消息开始聊天。`;
        }
      }
      const messageObj = ChatMessage.createEphemeralAssistant(
        message,
        LocalMessageIdPool.getNextId()
      );
      messageObj.actions = actions;
      return messageObj;
    },
    getEmptyMessage: () => EMPTY_MESSAGE,
  }
}

export type ChatStaticMessagesManager = ReturnType<typeof useChatStaticMessages>;