package com.lingyue.graph.dto;

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

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

/**
 * 数据源取值返回
 * 
 * @author lingyue
 * @since 2026-01-21
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "数据源取值返回")
public class DataSourceValue {
    
    public static final String TYPE_TEXT = "text";
    public static final String TYPE_IMAGE = "image";
    public static final String TYPE_TABLE = "table";
    public static final String TYPE_MIXED = "mixed";
    
    @Schema(description = "数据源ID")
    private String dataSourceId;
    
    @Schema(description = "数据源名称")
    private String dataSourceName;
    
    @Schema(description = "值类型", example = "text/image/table/mixed")
    private String type;
    
    @Schema(description = "文本值（聚合后）")
    private String textValue;
    
    @Schema(description = "图片URL")
    private String imageUrl;
    
    @Schema(description = "图片路径")
    private String imagePath;
    
    @Schema(description = "表格数据")
    private List<List<Map<String, Object>>> tableData;
    
    @Schema(description = "原始节点值列表")
    private List<NodeValueItem> items;
    
    @Schema(description = "节点数量")
    private Integer nodeCount;
    
    /**
     * 创建空值
     */
    public static DataSourceValue empty(String dataSourceId, String dataSourceName) {
        return DataSourceValue.builder()
                .dataSourceId(dataSourceId)
                .dataSourceName(dataSourceName)
                .type(TYPE_TEXT)
                .textValue("")
                .nodeCount(0)
                .build();
    }
    
    /**
     * 创建文本值
     */
    public static DataSourceValue text(String dataSourceId, String dataSourceName, String value, List<NodeValueItem> items) {
        return DataSourceValue.builder()
                .dataSourceId(dataSourceId)
                .dataSourceName(dataSourceName)
                .type(TYPE_TEXT)
                .textValue(value)
                .items(items)
                .nodeCount(items != null ? items.size() : 0)
                .build();
    }
    
    /**
     * 创建图片值
     */
    public static DataSourceValue image(String dataSourceId, String dataSourceName, String imageUrl, String imagePath, List<NodeValueItem> items) {
        return DataSourceValue.builder()
                .dataSourceId(dataSourceId)
                .dataSourceName(dataSourceName)
                .type(TYPE_IMAGE)
                .imageUrl(imageUrl)
                .imagePath(imagePath)
                .items(items)
                .nodeCount(items != null ? items.size() : 0)
                .build();
    }
    
    /**
     * 创建表格值
     */
    public static DataSourceValue table(String dataSourceId, String dataSourceName, List<List<Map<String, Object>>> tableData, List<NodeValueItem> items) {
        return DataSourceValue.builder()
                .dataSourceId(dataSourceId)
                .dataSourceName(dataSourceName)
                .type(TYPE_TABLE)
                .tableData(tableData)
                .items(items)
                .nodeCount(items != null ? items.size() : 0)
                .build();
    }
}
