"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.register = register;
const zod_1 = require("zod");
const defaults_1 = require("../../../lib/defaults");
function register(server, mgr) {
    server.registerTool('skills_create_link', {
        description: 'Link a skill to another skill (same-graph) or to a node in the docs, code, files, knowledge, or tasks graph (cross-graph). ' +
            'Omit targetGraph for same-graph skill-to-skill links; set it for cross-graph links. ' +
            'The kind is a free-form string, e.g. "references", "implements", "documents".',
        inputSchema: {
            skillId: zod_1.z.string().min(1).max(500).describe('Source skill ID'),
            targetId: zod_1.z.string().min(1).max(defaults_1.MAX_TARGET_NODE_ID_LEN).describe('Target skill ID (same-graph) or target node ID in external graph (cross-graph)'),
            targetGraph: zod_1.z.enum(['docs', 'code', 'files', 'knowledge', 'tasks']).optional()
                .describe('Target graph: "docs", "code", "files", "knowledge", or "tasks". Omit for skill-to-skill links.'),
            kind: zod_1.z.string().min(1).max(defaults_1.MAX_LINK_KIND_LEN).describe('Relation type, e.g. "references", "implements", "documents"'),
            projectId: zod_1.z.string().max(defaults_1.MAX_PROJECT_ID_LEN).optional().describe('Project ID that the target node belongs to. Defaults to the current project.'),
        },
    }, async ({ skillId, targetId, targetGraph, kind, projectId }) => {
        if (targetGraph) {
            const created = mgr.createCrossLink(skillId, targetId, targetGraph, kind, projectId);
            if (!created) {
                return { content: [{ type: 'text', text: 'Could not create cross-graph link — skill not found, target not found, or link already exists.' }], isError: true };
            }
            return { content: [{ type: 'text', text: JSON.stringify({ skillId, targetId, targetGraph, kind, created: true }, null, 2) }] };
        }
        // Same-graph skill-to-skill link
        const created = mgr.linkSkills(skillId, targetId, kind);
        if (!created) {
            return { content: [{ type: 'text', text: 'Could not create link — one or both skills not found, or link already exists.' }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify({ skillId, targetId, kind, created: true }, null, 2) }] };
    });
}
