"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.pruneSchema = exports.addEscalationChainSchema = exports.createRoleSchema = exports.listRolesSchema = exports.removeUserRoleSchema = exports.addUserRoleSchema = exports.createUserSchema = exports.listUsersSchema = exports.invokeYamlWorkflowSchema = exports.deployYamlWorkflowSchema = exports.createYamlWorkflowSchema = exports.getYamlWorkflowSchema = exports.listYamlWorkflowsSchema = exports.disconnectMcpServerSchema = exports.connectMcpServerSchema = exports.updateMcpServerSchema = exports.listMcpServersSchema = exports.getWorkflowStatusSchema = exports.invokeWorkflowSchema = exports.listDiscoveredWorkflowsSchema = exports.deleteWorkflowConfigSchema = exports.upsertWorkflowConfigSchema = exports.listWorkflowConfigsSchema = exports.bulkTriageSchema = exports.releaseExpiredClaimsSchema = exports.claimEscalationSchema = exports.getEscalationStatsSchema = exports.findEscalationsSchema = exports.getProcessDetailSchema = exports.findTasksSchema = void 0;
/**
 * Zod schemas for the admin MCP server tools.
 *
 * Each schema mirrors the exact parameter shape of the corresponding
 * REST API route handler. When a route accepts `req.query.status`,
 * the schema has `status: z.string().optional()`. When a route
 * reads `req.body.roles`, the schema has `roles: z.array(...)`.
 *
 * Schemas are extracted here (rather than inline) to avoid TS2589
 * deep-instantiation errors in the registerTool() generic.
 */
const zod_1 = require("zod");
// ── tasks (routes/tasks.ts) ─────────────────────────────────────────────────
exports.findTasksSchema = zod_1.z.object({
    status: zod_1.z.string().optional().describe('Filter: pending, completed, etc.'),
    workflow_type: zod_1.z.string().optional().describe('Filter by workflow type name'),
    workflow_id: zod_1.z.string().optional().describe('Filter by workflow execution ID'),
    origin_id: zod_1.z.string().optional().describe('Filter by origin/process ID'),
    limit: zod_1.z.number().int().min(1).max(100).optional().default(25),
    offset: zod_1.z.number().int().min(0).optional().default(0),
});
exports.getProcessDetailSchema = zod_1.z.object({
    origin_id: zod_1.z.string().describe('The origin ID (process ID) to look up'),
});
// ── escalations (routes/escalations/) ───────────────────────────────────────
exports.findEscalationsSchema = zod_1.z.object({
    status: zod_1.z.enum(['pending', 'resolved']).optional().describe('Filter by status'),
    role: zod_1.z.string().optional().describe('Filter by target role'),
    type: zod_1.z.string().optional().describe('Filter by escalation type'),
    priority: zod_1.z.number().int().min(1).max(4).optional().describe('Filter by priority (1=critical, 4=low)'),
    limit: zod_1.z.number().int().min(1).max(100).optional().default(25),
    offset: zod_1.z.number().int().min(0).optional().default(0),
});
exports.getEscalationStatsSchema = zod_1.z.object({
    period: zod_1.z.string().optional().describe('Time period: 1h, 24h, 7d, 30d'),
});
exports.claimEscalationSchema = zod_1.z.object({
    id: zod_1.z.string().describe('Escalation UUID'),
    duration_minutes: zod_1.z.number().int().optional().default(30)
        .describe('Lock duration in minutes'),
});
exports.releaseExpiredClaimsSchema = zod_1.z.object({});
exports.bulkTriageSchema = zod_1.z.object({
    ids: zod_1.z.array(zod_1.z.string()).min(1).describe('Escalation UUIDs to triage'),
    hint: zod_1.z.string().optional().describe('Remediation hint for the triage agent'),
});
// ── workflow config (routes/workflows/config.ts) ────────────────────────────
exports.listWorkflowConfigsSchema = zod_1.z.object({});
exports.upsertWorkflowConfigSchema = zod_1.z.object({
    workflow_type: zod_1.z.string().describe('Workflow function name'),
    invocable: zod_1.z.boolean().optional().default(false),
    task_queue: zod_1.z.string().nullable().optional().default(null),
    default_role: zod_1.z.string().optional().default('reviewer'),
    description: zod_1.z.string().nullable().optional().default(null),
    execute_as: zod_1.z.string().nullable().optional().default(null)
        .describe('Bot external_id to run as'),
    roles: zod_1.z.array(zod_1.z.string()).optional().default([]),
    invocation_roles: zod_1.z.array(zod_1.z.string()).optional().default([]),
    consumes: zod_1.z.array(zod_1.z.string()).optional().default([]),
    tool_tags: zod_1.z.array(zod_1.z.string()).optional().default([]),
    envelope_schema: zod_1.z.record(zod_1.z.any()).nullable().optional().default(null),
    resolver_schema: zod_1.z.record(zod_1.z.any()).nullable().optional().default(null),
    cron_schedule: zod_1.z.string().nullable().optional().default(null),
});
exports.deleteWorkflowConfigSchema = zod_1.z.object({
    workflow_type: zod_1.z.string().describe('Workflow type to de-certify'),
});
// ── workflows (routes/workflows/invocation.ts + discovery.ts) ───────────────
exports.listDiscoveredWorkflowsSchema = zod_1.z.object({
    include_system: zod_1.z.boolean().optional().default(false),
});
exports.invokeWorkflowSchema = zod_1.z.object({
    workflow_type: zod_1.z.string().describe('Registered workflow type name'),
    data: zod_1.z.record(zod_1.z.any()).describe('Business data for envelope.data'),
    metadata: zod_1.z.record(zod_1.z.any()).optional().describe('Control flow metadata'),
    execute_as: zod_1.z.string().optional().describe('Bot external_id override (admin only)'),
});
exports.getWorkflowStatusSchema = zod_1.z.object({
    workflow_id: zod_1.z.string().describe('HotMesh workflow ID'),
});
// ── mcp servers (routes/mcp.ts) ─────────────────────────────────────────────
exports.listMcpServersSchema = zod_1.z.object({
    status: zod_1.z.string().optional().describe('Filter: registered, connected, error, disconnected'),
    tags: zod_1.z.string().optional().describe('Comma-separated tag filter'),
    search: zod_1.z.string().optional().describe('Search name, description, or tool names'),
    limit: zod_1.z.number().int().min(1).max(100).optional().default(50),
    offset: zod_1.z.number().int().min(0).optional().default(0),
});
exports.updateMcpServerSchema = zod_1.z.object({
    id: zod_1.z.string().describe('Server UUID'),
    name: zod_1.z.string().optional(),
    description: zod_1.z.string().optional(),
    tags: zod_1.z.array(zod_1.z.string()).optional(),
    auto_connect: zod_1.z.boolean().optional(),
});
exports.connectMcpServerSchema = zod_1.z.object({
    id: zod_1.z.string().describe('Server UUID to connect'),
});
exports.disconnectMcpServerSchema = zod_1.z.object({
    id: zod_1.z.string().describe('Server UUID to disconnect'),
});
// ── yaml workflows (routes/yaml-workflows/) ─────────────────────────────────
exports.listYamlWorkflowsSchema = zod_1.z.object({
    status: zod_1.z.string().optional().describe('Filter: draft, deployed, active, archived'),
    app_id: zod_1.z.string().optional().describe('Filter by namespace'),
    search: zod_1.z.string().optional().describe('Search name, topic, description'),
    source_workflow_id: zod_1.z.string().optional(),
    limit: zod_1.z.number().int().min(1).max(100).optional().default(50),
    offset: zod_1.z.number().int().min(0).optional().default(0),
});
exports.getYamlWorkflowSchema = zod_1.z.object({
    id: zod_1.z.string().describe('YAML workflow UUID'),
});
exports.createYamlWorkflowSchema = zod_1.z.object({
    workflow_id: zod_1.z.string().describe('Source execution workflow ID'),
    task_queue: zod_1.z.string().describe('Task queue of the source execution'),
    workflow_name: zod_1.z.string().describe('Source workflow type name'),
    name: zod_1.z.string().describe('Name for the new compiled workflow'),
    description: zod_1.z.string().optional(),
    app_id: zod_1.z.string().optional().describe('Namespace (auto-generated if omitted)'),
    tags: zod_1.z.array(zod_1.z.string()).optional().describe('Discovery tags'),
    compilation_feedback: zod_1.z.string().optional().describe('Extra instructions for the compiler'),
});
exports.deployYamlWorkflowSchema = zod_1.z.object({
    id: zod_1.z.string().describe('YAML workflow UUID to deploy'),
});
exports.invokeYamlWorkflowSchema = zod_1.z.object({
    id: zod_1.z.string().describe('YAML workflow UUID'),
    data: zod_1.z.record(zod_1.z.any()).optional().default({}).describe('Input matching the workflow input_schema'),
    sync: zod_1.z.boolean().optional().default(false).describe('Wait for result'),
    timeout: zod_1.z.number().int().optional().describe('Timeout in ms for sync mode'),
});
// ── users (routes/users.ts) ─────────────────────────────────────────────────
exports.listUsersSchema = zod_1.z.object({
    role: zod_1.z.string().optional().describe('Filter by role name'),
    status: zod_1.z.string().optional().describe('Filter: active, inactive, suspended'),
    limit: zod_1.z.number().int().min(1).max(100).optional().default(50),
    offset: zod_1.z.number().int().min(0).optional().default(0),
});
exports.createUserSchema = zod_1.z.object({
    external_id: zod_1.z.string().describe('Stable user identifier'),
    display_name: zod_1.z.string().optional(),
    email: zod_1.z.string().optional(),
    roles: zod_1.z.array(zod_1.z.object({
        role: zod_1.z.string(),
        type: zod_1.z.enum(['superadmin', 'admin', 'member']),
    })).optional().default([]).describe('Roles to assign on creation'),
});
exports.addUserRoleSchema = zod_1.z.object({
    user_id: zod_1.z.string().describe('User UUID'),
    role: zod_1.z.string().describe('Role name'),
    type: zod_1.z.enum(['superadmin', 'admin', 'member']).describe('Permission level'),
});
exports.removeUserRoleSchema = zod_1.z.object({
    user_id: zod_1.z.string().describe('User UUID'),
    role: zod_1.z.string().describe('Role to remove'),
});
// ── roles (routes/roles.ts) ─────────────────────────────────────────────────
exports.listRolesSchema = zod_1.z.object({});
exports.createRoleSchema = zod_1.z.object({
    role: zod_1.z.string().describe('Lowercase alphanumeric role name (a-z, 0-9, hyphens, underscores)'),
});
exports.addEscalationChainSchema = zod_1.z.object({
    source_role: zod_1.z.string().describe('Originating role'),
    target_role: zod_1.z.string().describe('Destination role for escalation'),
});
// ── maintenance (routes/dba.ts) ─────────────────────────────────────────────
exports.pruneSchema = zod_1.z.object({
    expire: zod_1.z.string().optional().default('7 days').describe('Retention period (PostgreSQL interval)'),
    jobs: zod_1.z.boolean().optional().default(true).describe('Hard-delete expired jobs'),
    streams: zod_1.z.boolean().optional().default(true).describe('Hard-delete expired streams'),
    entities: zod_1.z.array(zod_1.z.string()).optional().describe('Entity allowlist'),
    prune_transient: zod_1.z.boolean().optional().default(false).describe('Delete transient jobs'),
});
