package cn.teammodel.model.entity.ai;

import cn.hutool.core.lang.UUID;
import cn.teammodel.model.entity.BaseItem;
import com.azure.spring.data.cosmos.core.mapping.Container;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;

import java.time.Instant;
import java.util.List;

/**
 * 聊天会话,绑定 teacherId(userId), 主键id: sessionId
 * @author winter
 * @create 2023-12-19 15:09
 */
@EqualsAndHashCode(callSuper = true)
@Container(containerName = "Teacher")
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChatSession extends BaseItem {
    /**
    * 会话名称
    */
    private String title;
    /**
    * 用户 id
    */
    private String userId;
    private Long createTime;
    /**
    * 产生对话即更新时间,按更新时间排序
    */
    private Long updateTime;
    private List<Message> history;

    @Data
    public static class Message {
        private String id;
        private String userText;
        private String gptText;
        /**
        * 消耗的 point
        */
        private Integer cost;
        private Long createTime;

        public static Message of(String userText, String gptText) {
            Message message = new Message();
            message.setId(UUID.randomUUID().toString());
            message.setCost(0);
            message.setUserText(userText);
            message.setGptText(gptText);
            message.setCreateTime(Instant.now().toEpochMilli());
            return message;
        }
    }
}
