package top.tqx.demo_1.dto;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(description = "题目生成响应")
public class ExamGenerateResponse implements Serializable {

    private static final long serialVersionUID = 1L;

    @JsonProperty("success")
    @Schema(description = "是否成功")
    private Boolean success;

    @JsonProperty("message")
    @Schema(description = "消息")
    private String message;

    @JsonProperty("status")
    @Schema(description = "状态")
    private String status;

    @JsonProperty("status_code")
    @Schema(description = "状态码")
    private Integer statusCode;

    @JsonProperty("request_id")
    @Schema(description = "请求ID")
    private String requestId;

    @JsonProperty("total")
    @Schema(description = "题目总数")
    private Integer total;

    @JsonProperty("source_chunks_used")
    @Schema(description = "使用的源文档块数量")
    private Integer sourceChunksUsed;

    @JsonProperty("error")
    @Schema(description = "错误信息")
    private String error;

    @JsonProperty("error_code")
    @Schema(description = "错误码")
    private String errorCode;

    @JsonProperty("data")
    @Schema(description = "响应数据")
    private ResponseData data;

    @JsonProperty("ai_analysis")
    @Schema(description = "AI分析结果，包含文档摘要、题型分布等信息")
    private Object aiAnalysis;

    @JsonProperty("questions")
    @Schema(description = "生成的题目列表")
    private List<ExamGenerateRequest.Question> questions;

    @Data
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class ResponseData implements Serializable {
        private static final long serialVersionUID = 1L;

        @JsonProperty("ai_analysis")
        private Object aiAnalysis;

        @JsonProperty("questions")
        private List<ExamGenerateRequest.Question> questions;

        @JsonProperty("total")
        private Integer total;

        @JsonProperty("source_chunks_used")
        private Integer sourceChunksUsed;

        @JsonProperty("request_id")
        private String requestId;

        @JsonProperty("success")
        private Boolean success;
    }

    public Object getAiAnalysis() {
        if (aiAnalysis != null) {
            return aiAnalysis;
        }
        if (data != null) {
            return data.getAiAnalysis();
        }
        return null;
    }

    public List<ExamGenerateRequest.Question> getQuestions() {
        if (questions != null && !questions.isEmpty()) {
            return questions;
        }
        if (data != null && data.getQuestions() != null) {
            return data.getQuestions();
        }
        return null;
    }

    public Integer getTotal() {
        if (total != null) {
            return total;
        }
        if (data != null && data.getTotal() != null) {
            return data.getTotal();
        }
        return null;
    }

    public Integer getSourceChunksUsed() {
        if (sourceChunksUsed != null) {
            return sourceChunksUsed;
        }
        if (data != null && data.getSourceChunksUsed() != null) {
            return data.getSourceChunksUsed();
        }
        return null;
    }

    public String getRequestId() {
        if (requestId != null) {
            return requestId;
        }
        if (data != null && data.getRequestId() != null) {
            return data.getRequestId();
        }
        return null;
    }

    public Boolean getSuccess() {
        if (success != null) {
            return success;
        }
        if (data != null && data.getSuccess() != null) {
            return data.getSuccess();
        }
        return null;
    }
}
