package com.lingyue.extract.dto.response;

import com.lingyue.extract.entity.SourceFile;
import com.lingyue.extract.entity.Template;
import com.lingyue.extract.entity.Variable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 模板详情响应
 * 
 * @author lingyue
 * @since 2026-01-23
 */
@Data
@Schema(description = "模板详情响应")
public class TemplateDetailResponse {
    
    @Schema(description = "模板ID")
    private String id;
    
    @Schema(description = "用户ID")
    private String userId;
    
    @Schema(description = "模板名称")
    private String name;
    
    @Schema(description = "模板描述")
    private String description;
    
    @Schema(description = "示例报告文档ID")
    private String baseDocumentId;
    
    @Schema(description = "状态: draft/published/archived")
    private String status;
    
    @Schema(description = "模板配置")
    private Map<String, Object> config;
    
    @Schema(description = "是否公开")
    private Boolean isPublic;
    
    @Schema(description = "使用次数")
    private Integer useCount;
    
    @Schema(description = "创建时间")
    private Date createTime;
    
    @Schema(description = "更新时间")
    private Date updateTime;
    
    // ==================== 关联数据 ====================
    
    @Schema(description = "来源文件定义列表")
    private List<SourceFile> sourceFiles;
    
    @Schema(description = "变量列表")
    private List<Variable> variables;
    
    // ==================== 统计信息 ====================
    
    @Schema(description = "来源文件数量")
    private Integer sourceFileCount;
    
    @Schema(description = "变量数量")
    private Integer variableCount;
    
    @Schema(description = "生成次数")
    private Integer generationCount;
    
    /**
     * 从实体转换
     */
    public static TemplateDetailResponse fromEntity(Template template) {
        TemplateDetailResponse response = new TemplateDetailResponse();
        response.setId(template.getId());
        response.setUserId(template.getUserId());
        response.setName(template.getName());
        response.setDescription(template.getDescription());
        response.setBaseDocumentId(template.getBaseDocumentId());
        response.setStatus(template.getStatus());
        response.setConfig(template.getConfig());
        response.setIsPublic(template.getIsPublic());
        response.setUseCount(template.getUseCount());
        response.setCreateTime(template.getCreateTime());
        response.setUpdateTime(template.getUpdateTime());
        return response;
    }
}
