package com.lingyue.extract.dto.response;

import com.lingyue.extract.dto.config.VariableLocation;
import com.lingyue.extract.entity.Variable;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

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

/**
 * 变量响应
 * 
 * @author lingyue
 * @since 2026-01-23
 */
@Data
@Schema(description = "变量响应")
public class VariableResponse {
    
    @Schema(description = "ID")
    private String id;
    
    @Schema(description = "模板ID")
    private String templateId;
    
    @Schema(description = "变量名")
    private String name;
    
    @Schema(description = "显示名称")
    private String displayName;
    
    @Schema(description = "变量分组")
    private String variableGroup;
    
    @Schema(description = "变量类别（前端显示用）: entity/concept/data/location/asset")
    private String category;
    
    @Schema(description = "变量位置")
    private VariableLocation location;
    
    @Schema(description = "示例值")
    private String exampleValue;
    
    @Schema(description = "值类型")
    private String valueType;
    
    @Schema(description = "来源文件别名")
    private String sourceFileAlias;
    
    @Schema(description = "来源类型")
    private String sourceType;
    
    @Schema(description = "来源配置")
    private Map<String, Object> sourceConfig;
    
    @Schema(description = "提取类型")
    private String extractType;
    
    @Schema(description = "提取配置")
    private Map<String, Object> extractConfig;
    
    @Schema(description = "显示顺序")
    private Integer displayOrder;
    
    @Schema(description = "创建时间")
    private Date createTime;
    
    @Schema(description = "更新时间")
    private Date updateTime;
    
    /**
     * 从实体转换
     */
    public static VariableResponse fromEntity(Variable variable) {
        VariableResponse response = new VariableResponse();
        response.setId(variable.getId());
        response.setTemplateId(variable.getTemplateId());
        response.setName(variable.getName());
        response.setDisplayName(variable.getDisplayName());
        response.setVariableGroup(variable.getVariableGroup());
        response.setCategory(variable.getCategory());
        response.setLocation(variable.getLocation());
        response.setExampleValue(variable.getExampleValue());
        response.setValueType(variable.getValueType());
        response.setSourceFileAlias(variable.getSourceFileAlias());
        response.setSourceType(variable.getSourceType());
        response.setSourceConfig(variable.getSourceConfig());
        response.setExtractType(variable.getExtractType());
        response.setExtractConfig(variable.getExtractConfig());
        response.setDisplayOrder(variable.getDisplayOrder());
        response.setCreateTime(variable.getCreateTime());
        response.setUpdateTime(variable.getUpdateTime());
        return response;
    }
}
