package handlers

import (
	"fmt"

	"start-feishubot/services/openai"
)

type MessageAction struct { /*æ¶ˆæ�¯*/
}

func (*MessageAction) Execute(a *ActionInfo) bool {
	msg := a.handler.sessionCache.GetMsg(*a.info.sessionId)
	msg = append(msg, openai.Messages{
		Role: "user", Content: a.info.qParsed,
	})
	// get ai mode as temperature
	aiMode := a.handler.sessionCache.GetAIMode(*a.info.sessionId)
	completions, err := a.handler.gpt.Completions(msg, aiMode)
	if err != nil {
		replyMsg(*a.ctx, fmt.Sprintf(
			"ğŸ¤–ï¸�ï¼šæ¶ˆæ�¯æœºå™¨äººæ‘†çƒ‚äº†ï¼Œè¯·ç¨�å��å†�è¯•ï½�\né”™è¯¯ä¿¡æ�¯: %v", err), a.info.msgId)
		return false
	}
	msg = append(msg, completions)
	a.handler.sessionCache.SetMsg(*a.info.sessionId, msg)
	//if new topic
	if len(msg) == 2 {
		//fmt.Println("new topic", msg[1].Content)
		sendNewTopicCard(*a.ctx, a.info.sessionId, a.info.msgId,
			completions.Content)
		return false
	}
	err = replyMsg(*a.ctx, completions.Content, a.info.msgId)
	if err != nil {
		replyMsg(*a.ctx, fmt.Sprintf(
			"ğŸ¤–ï¸�ï¼šæ¶ˆæ�¯æœºå™¨äººæ‘†çƒ‚äº†ï¼Œè¯·ç¨�å��å†�è¯•ï½�\né”™è¯¯ä¿¡æ�¯: %v", err), a.info.msgId)
		return false
	}
	return true
}
