package com.seer.teach.teacher.common.llm.sse.req;

import com.seer.teach.teacher.common.req.StudyReq;
import com.seer.teach.teacher.common.utils.TeacherUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Collections;
import java.util.List;

/**
 *
 * <p>
 *
 * </p >
 *
 * @author Captain
 * @since 2025-09-29 16:45
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class LlmSseStudyReq {

    private Integer sessionId;

    private Integer userId;

    private Integer knowId;

    private Integer loopId;

    private Integer videoIndex;

    private Integer audioInterruptId;

    private Boolean finishedPlayingVideo;

    private Boolean studentAnswer;

    private List<Message> messages;

    public static LlmSseStudyReq firstStudy(StudyReq params, Integer userId) {
        LlmSseStudyReq llmSseStudyReq = new LlmSseStudyReq();
        llmSseStudyReq.setUserId(userId);
        llmSseStudyReq.setKnowId(params.getId());
        llmSseStudyReq.setFinishedPlayingVideo(false);
        llmSseStudyReq.setStudentAnswer(false);
        llmSseStudyReq.setVideoIndex(1);
        Integer sessionId = TeacherUtils.generateSessionId(params, userId);
        llmSseStudyReq.setSessionId(sessionId);
        return llmSseStudyReq;
    }

    public static LlmSseStudyReq continueStudy(Integer userId, Integer knowId, Integer videoIndex) {
        LlmSseStudyReq llmSseStudyReq = new LlmSseStudyReq();
        llmSseStudyReq.setUserId(userId);
        llmSseStudyReq.setVideoIndex(videoIndex);
        llmSseStudyReq.setFinishedPlayingVideo(true);
        llmSseStudyReq.setStudentAnswer(false);
        llmSseStudyReq.setKnowId(knowId);
        llmSseStudyReq.setAudioInterruptId(null);
        llmSseStudyReq.setLoopId(null);
        Integer sessionId = TeacherUtils.generateSessionId(userId, videoIndex, knowId);
        llmSseStudyReq.setSessionId(sessionId);
        return llmSseStudyReq;
    }

    public static LlmSseStudyReq studyWithQuestion(Integer userId, Integer videoIndex, Integer knowId, Integer audioInterruptId, String userQuestion) {
        LlmSseStudyReq llmSseStudyReq = new LlmSseStudyReq();
        llmSseStudyReq.setUserId(userId);
        llmSseStudyReq.setVideoIndex(videoIndex);
        llmSseStudyReq.setAudioInterruptId(audioInterruptId);
        llmSseStudyReq.setFinishedPlayingVideo(false);
        llmSseStudyReq.setStudentAnswer(true);
        llmSseStudyReq.setKnowId(knowId);
        llmSseStudyReq.setLoopId(null);
        List<Text> text = Text.text(userQuestion);
        Message user = Message.user(text);
        llmSseStudyReq.setMessages(Collections.singletonList(user));
        Integer sessionId = TeacherUtils.generateSessionId(user, videoIndex, knowId, audioInterruptId, userQuestion);
        llmSseStudyReq.setSessionId(sessionId);
        return llmSseStudyReq;
    }

}
