package v1

import (
	"database/sql"
	"time"
)

type Message struct {
	ID               string       `json:"id" gorm:"primary_key;column:id"`
	CreatedAt        time.Time    `json:"createdAt" gorm:"column:createdAt"`
	UpdatedAt        sql.NullTime `json:"updatedAt" gorm:"column:updatedAt"`
	Scene            string       `json:"scene" gorm:"column:scene"`
	PID              string       `json:"pid" gorm:"column:pid"`
	Content          string       `json:"content" gorm:"column:content"`
	SenderLarkID     string       `json:"senderLarkID" gorm:"column:senderLarkID"`
	SenderType       string       `json:"senderType" gorm:"column:senderType"`
	ReceiverLarkID   string       `json:"receiverLarkID" gorm:"column:receiverLarkID"`
	ReceiverType     string       `json:"receiverType" gorm:"column:receiverType"`
	MsgType          string       `json:"msgType" gorm:"column:msgType"`
	FlatParentIDs    string       `json:"flatParentIDs" gorm:"column:flatParentIDs"`
	Semantic         string       `json:"semantic" gorm:"column:semantic"`
	TotalTokens      int          `json:"totalTokens" gorm:"column:totalTokens"`
	PromptTokens     int          `json:"promptTokens" gorm:"column:promptTokens"`
	CompletionTokens int          `json:"completionTokens" gorm:"column:completionTokens"`
	Model            string       `json:"model" gorm:"column:model"`
}

func (m *Message) TableName() string {
	return "message"
}

const (
	FinishThreadOnGoing  = 0
	FinishThreadFinished = 1
)

const (
	SemanticEndSession = "EndSession"
)

const (
	SceneLarkP2P   = "LarkP2P"
	SceneGeneral   = "General"
	SceneLarkGroup = "LarkGroup"
)

const (
	SubjectTypePingCat = "PingCat"
	SubjectTypeUser    = "User"
	SubjectTypeGroup   = "Group"
)

type GPTChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type GPTChatOption struct {
	Temperature float32 `json:"temperature"`
	TopP        float32 `json:"topP"`
	N           int     `json:"n"`
	MaxTokens   int     `json:"maxTokens"`
}

type GPTChatRes struct {
	Content string        `json:"content"`
	Role    string        `json:"role"`
	Usage   GPTTokenUsage `json:"usage"`
	Model   string        `json:"model"`
}

type GPTTokenUsage struct {
	Total      int `json:"total"`
	Prompt     int `json:"prompt"`
	Completion int `json:"completion"`
}

//type MessageResDataMsg struct {
//	ID            string                `json:"id"`
//	CreatedAt     time.Time             `json:"createdAt"`
//	PID           string                `json:"pid"`
//	Content       string                `json:"content"`
//	Sender        MessageResDataSubject `json:"sender"`
//	Receiver      MessageResDataSubject `json:"receiver"`
//	MsgType       string                `json:"msgType"`
//	FlatParentIDs string                `json:"flatParentIDs"`
//}

type MessageResData struct {
	InMsg  Message             `json:"inMsg"`
	OutMsg Message             `json:"outMsg"`
	Extra  MessageResDataExtra `json:"extra"`
}

type MessageResDataExtra struct {
	GPTTokenUsage *GPTTokenUsage `json:"gptTokenUsage"`
	GPTOptions    *GPTChatOption `json:"gptOptions"`
}

type MessageResDataSubject struct {
	LarkID string `json:"larkID"`
	Type   string `json:"type"`
	Avatar string `json:"avatar"`
}

type MsgReqData struct {
	PID     string         `json:"pid"`
	Msg     string         `json:"msg"`
	Options *GPTChatOption `json:"options"`
}

const (
	P2PHelpInfo   = "Hi, I'm an in-house GPT-3.5-powered assistant to PingCAP. As you see, I'm a cat, and my avatar is created by Midjourney(another famous image AI), miaow~\n\n- You can send me a plain text message, and I'll reply.\n- If you want to start a new conversation, send me '+++' or '---' or '===' or 'clear'. Then I will forget the previous content and start a new conversation.\n\nIf you want to know more about me, please talk in the lark group called 'Ask PingCAT'."                                                                                                                                                                                                                              //nolint:lll // acceptable
	GroupHelpInfo = "Hi, I'm an in-house GPT-3.5-powered assistant to PingCAP. As you see, I'm a cat, and my avatar is created by Midjourney(another famous image AI), miaow~\n\nChatting with me in a group is a little different from talking to me in p2p.\n- When you want to chat with me in a group, you must @PingCAT. I can not receive any message without @PingCAT in a group.\n- If you want to start a new conversation, send a plain text message with @PingCAT, and I'll reply.\n- If you want to continue the previous conversation, you can quote one message or directly reply to my message. Note that @PingCAT. \n\nIf you want to know more about me, please talk in the lark group called 'Ask PingCAT'." //nolint:lll // acceptable
)
