package com.ruoyi.llm.domain;

/**
 * 章节流式响应DTO
 */
public class ChapterStreamResponse {

    /**
     * 章节标题
     */
    private String title;

    /**
     * 当前章节内容片段
     */
    private String content;

    /**
     * 是否是当前章节的最后一块内容
     */
    private boolean isLast;

    /**
     * 当前章节索引（从1开始）
     */
    private int chapterIndex;

    /**
     * 总章节数
     */
    private int totalChapters;

    /**
     * 是否发生错误
     */
    private boolean error;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 是否全部完成
     */
    private boolean completed;

    /**
     * 提示词token数量
     */
    private long promptTokens;

    /**
     * 完成token数量
     */
    private long completionTokens;

    /**
     * 总token数量
     */
    private long totalTokens;

    public ChapterStreamResponse() {
    }

    public static ChapterStreamResponse content(String title, String content, boolean isLast, int chapterIndex, int totalChapters) {
        ChapterStreamResponse response = new ChapterStreamResponse();
        response.title = title;
        response.content = content;
        response.isLast = isLast;
        response.chapterIndex = chapterIndex;
        response.totalChapters = totalChapters;
        response.error = false;
        response.completed = false;
        return response;
    }

    public static ChapterStreamResponse error(String title, String errorMessage) {
        ChapterStreamResponse response = new ChapterStreamResponse();
        response.title = title;
        response.content = "该章节内容生成失败，请手动填写。";
        response.isLast = true;
        response.error = true;
        response.errorMessage = errorMessage;
        response.completed = false;
        return response;
    }

    public static ChapterStreamResponse completed() {
        ChapterStreamResponse response = new ChapterStreamResponse();
        response.completed = true;
        response.isLast = true;
        return response;
    }

    public static ChapterStreamResponse progress(String progressMessage) {
        ChapterStreamResponse response = new ChapterStreamResponse();
        response.content = progressMessage;
        response.completed = false;
        response.isLast = false;
        return response;
    }

    // Getters and Setters
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public boolean isLast() {
        return isLast;
    }

    public void setLast(boolean last) {
        isLast = last;
    }

    public int getChapterIndex() {
        return chapterIndex;
    }

    public void setChapterIndex(int chapterIndex) {
        this.chapterIndex = chapterIndex;
    }

    public int getTotalChapters() {
        return totalChapters;
    }

    public void setTotalChapters(int totalChapters) {
        this.totalChapters = totalChapters;
    }

    public boolean isError() {
        return error;
    }

    public void setError(boolean error) {
        this.error = error;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }

    public boolean isCompleted() {
        return completed;
    }

    public void setCompleted(boolean completed) {
        this.completed = completed;
    }

    public long getPromptTokens() {
        return promptTokens;
    }

    public void setPromptTokens(long promptTokens) {
        this.promptTokens = promptTokens;
    }

    public long getCompletionTokens() {
        return completionTokens;
    }

    public void setCompletionTokens(long completionTokens) {
        this.completionTokens = completionTokens;
    }

    public long getTotalTokens() {
        return totalTokens;
    }

    public void setTotalTokens(long totalTokens) {
        this.totalTokens = totalTokens;
    }

    @Override
    public String toString() {
        return "ChapterStreamResponse{" +
                "title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", isLast=" + isLast +
                ", chapterIndex=" + chapterIndex +
                ", totalChapters=" + totalChapters +
                ", error=" + error +
                ", completed=" + completed +
                '}';
    }
}