package com.lingyue.graph.dto;

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

import java.util.ArrayList;
import java.util.List;

/**
 * 节点引用列表
 * 数据源的 nodeIds 字段结构
 * 
 * @author lingyue
 * @since 2026-01-21
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "节点引用列表")
public class NodeRefs {
    
    @Schema(description = "节点引用数组")
    private List<NodeRef> refs = new ArrayList<>();
    
    /**
     * 添加图节点引用
     */
    public NodeRefs addGraphNode(String id) {
        refs.add(NodeRef.graphNode(id));
        return this;
    }
    
    /**
     * 添加文档元素引用
     */
    public NodeRefs addDocumentElement(String id) {
        refs.add(NodeRef.documentElement(id));
        return this;
    }
    
    /**
     * 获取所有图节点ID
     */
    public List<String> getGraphNodeIds() {
        List<String> ids = new ArrayList<>();
        for (NodeRef ref : refs) {
            if (ref.isGraphNode()) {
                ids.add(ref.getId());
            }
        }
        return ids;
    }
    
    /**
     * 获取所有文档元素ID
     */
    public List<String> getDocumentElementIds() {
        List<String> ids = new ArrayList<>();
        for (NodeRef ref : refs) {
            if (ref.isDocumentElement()) {
                ids.add(ref.getId());
            }
        }
        return ids;
    }
    
    /**
     * 是否为空
     */
    public boolean isEmpty() {
        return refs == null || refs.isEmpty();
    }
    
    /**
     * 节点数量
     */
    public int size() {
        return refs == null ? 0 : refs.size();
    }
}
