"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('tasks_list', {
        description: 'List tasks with optional filters. ' +
            'Sorted by priority (critical first) then due date (earliest first, nulls last). ' +
            'Returns an array of { id, title, description, status, priority, tags, dueDate, estimate, completedAt, createdAt, updatedAt }. ' +
            'Use search_tasks for semantic search.',
        inputSchema: {
            status: zod_1.z.enum(['backlog', 'todo', 'in_progress', 'review', 'done', 'cancelled']).optional()
                .describe('Filter by status: "backlog", "todo", "in_progress", "review", "done", or "cancelled"'),
            priority: zod_1.z.enum(['critical', 'high', 'medium', 'low']).optional()
                .describe('Filter by priority: "critical", "high", "medium", or "low"'),
            tag: zod_1.z.string().max(defaults_1.MAX_TAG_LEN).optional().describe('Filter by tag (exact match, case-insensitive)'),
            filter: zod_1.z.string().max(500).optional().describe('Substring match on title or ID'),
            assignee: zod_1.z.string().max(defaults_1.MAX_ASSIGNEE_LEN).optional().describe('Filter by assignee (team member ID)'),
            limit: zod_1.z.number().int().min(1).max(1000).optional().describe('Max results (default 50)'),
            offset: zod_1.z.number().int().min(0).max(100_000).optional().describe('Offset for pagination (default 0)'),
        },
    }, async ({ status, priority, tag, filter, assignee, limit, offset }) => {
        const { results, total } = mgr.listTasks({ status, priority, tag, filter, assignee, limit, offset });
        const clean = (k, v) => (k !== '' && (v === null || (Array.isArray(v) && v.length === 0)) ? undefined : v);
        const output = results.map(({ version: _, ...r }) => r);
        return { content: [{ type: 'text', text: JSON.stringify({ results: output, total }, clean, 2) }] };
    });
}
