"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('epics_update', {
        description: 'Update an existing epic. Only provided fields are changed.',
        inputSchema: {
            epicId: zod_1.z.string().min(1).max(500).describe('Epic ID to update'),
            title: zod_1.z.string().min(1).max(defaults_1.MAX_TITLE_LEN).optional().describe('New title'),
            description: zod_1.z.string().max(defaults_1.MAX_DESCRIPTION_LEN).optional().describe('New description'),
            status: zod_1.z.enum(['open', 'in_progress', 'done', 'cancelled']).optional().describe('New status'),
            priority: zod_1.z.enum(['critical', 'high', 'medium', 'low']).optional().describe('New priority'),
            tags: zod_1.z.array(zod_1.z.string().max(defaults_1.MAX_TAG_LEN)).max(defaults_1.MAX_TAGS_COUNT).optional().describe('New tags'),
            version: zod_1.z.number().int().positive().optional().describe('Expected version for optimistic locking'),
        },
    }, async ({ epicId, title, description, status, priority, tags, version }) => {
        const patch = {};
        if (title !== undefined)
            patch.title = title;
        if (description !== undefined)
            patch.description = description;
        if (priority !== undefined)
            patch.priority = priority;
        if (tags !== undefined)
            patch.tags = tags;
        const ok = await mgr.updateEpic(epicId, patch, status, version);
        if (!ok)
            return { content: [{ type: 'text', text: 'Epic not found' }], isError: true };
        return { content: [{ type: 'text', text: JSON.stringify({ epicId, updated: true }, null, 2) }] };
    });
}
