"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_delete_link', {
        description: 'Remove a link from 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. ' +
            'Orphaned proxy nodes are cleaned up automatically.',
        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.'),
            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, projectId }) => {
        if (targetGraph) {
            const deleted = mgr.deleteCrossLink(skillId, targetId, targetGraph, projectId);
            if (!deleted) {
                return { content: [{ type: 'text', text: 'Cross-graph link not found.' }], isError: true };
            }
            return { content: [{ type: 'text', text: JSON.stringify({ skillId, targetId, targetGraph, deleted: true }, null, 2) }] };
        }
        // Same-graph skill-to-skill link
        const deleted = mgr.deleteSkillLink(skillId, targetId);
        if (!deleted) {
            return { content: [{ type: 'text', text: 'Link not found.' }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify({ skillId, targetId, deleted: true }, null, 2) }] };
    });
}
