import { v4 as uuidv4 } from 'uuid';

/**
 * 生成节点ID
 * 格式: sid_xxxxxxxx_xxxx_xxxx_xxxx_xxxxxxxxxxxx
 * 
 * @returns 节点唯一标识符
 * 
 * @example
 * generateNodeId() // => "sid_a1b2c3d4_5e6f_7g8h_9i0j_k1l2m3n4o5p6"
 */
export const generateNodeId = (): string => {
    return `sid_${uuidv4().replace(/-/g, '_')}`;
};

/**
 * 生成边ID
 * 格式: eid_xxxxxxxx_xxxx_xxxx_xxxx_xxxxxxxxxxxx
 * 
 * @returns 边唯一标识符
 * 
 * @example
 * generateEdgeId() // => "eid_a1b2c3d4_5e6f_7g8h_9i0j_k1l2m3n4o5p6"
 */
export const generateEdgeId = (): string => {
    return `eid_${uuidv4().replace(/-/g, '_')}`;
};

/**
 * 检查是否为有效的节点ID
 * 
 * @param id 待检查的ID
 * @returns 是否为有效的节点ID
 */
export const isValidNodeId = (id: string): boolean => {
    return /^sid_[a-f0-9_]{36}$/.test(id);
};

/**
 * 检查是否为有效的边ID
 * 
 * @param id 待检查的ID
 * @returns 是否为有效的边ID
 */
export const isValidEdgeId = (id: string): boolean => {
    return /^eid_[a-f0-9_]{36}$/.test(id);
};

