package com.lingyue.ai.dto.ner;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 关系抽取响应 DTO
 *
 * @author lingyue
 * @since 2026-01-19
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "关系抽取响应")
public class RelationResponse {

    @Schema(description = "文档ID")
    private String documentId;

    @Schema(description = "提取的关系列表")
    private List<RelationInfo> relations;

    @Schema(description = "处理耗时（毫秒）")
    private Long processingTime;

    @Schema(description = "关系数量")
    private Integer relationCount;

    @Schema(description = "是否成功")
    @Builder.Default
    private Boolean success = true;

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

    /**
     * 创建成功响应
     */
    public static RelationResponse success(String documentId, List<RelationInfo> relations, long processingTime) {
        return RelationResponse.builder()
                .documentId(documentId)
                .relations(relations)
                .relationCount(relations != null ? relations.size() : 0)
                .processingTime(processingTime)
                .success(true)
                .build();
    }

    /**
     * 创建失败响应
     */
    public static RelationResponse error(String documentId, String errorMessage) {
        return RelationResponse.builder()
                .documentId(documentId)
                .success(false)
                .errorMessage(errorMessage)
                .build();
    }
}
