// tools/register-event-tools.ts — Registers Event-Driven Contracts tool (SPEC-031)
import { z } from 'zod';
import { handleEventContracts } from './event-contracts.js';
import { safeLicensed } from './safe-handler.js';
export function registerEventTools(server) {
    // event_contracts — SPEC-031
    server.registerTool('event_contracts', {
        description: 'Manage event-driven architecture contracts: generate JSON Schema contracts for events, ' +
            'validate payloads, evolve schemas with backward-compatibility classification, ' +
            'and define Saga contracts for distributed transactions.',
        inputSchema: {
            subcommand: z
                .enum(['generate-contract', 'validate-contract', 'evolve-contract', 'saga-spec'])
                .describe('generate-contract: create a new event contract JSON Schema; ' +
                'validate-contract: verify a payload against the active contract; ' +
                'evolve-contract: classify a schema change and apply the new version; ' +
                'saga-spec: define a Saga with compensation events per step'),
            projectId: z.string().describe('Project ID (hash of project path)'),
            generateContract: z
                .object({
                projectId: z.string().describe('Project ID'),
                eventName: z.string().describe('Unique event name, e.g. "order.created"'),
                producer: z.string().describe('Service or component that emits this event'),
                consumers: z.array(z.string()).describe('Known consumer service names'),
                payloadFields: z
                    .array(z.object({
                    name: z.string().describe('Field name'),
                    type: z
                        .string()
                        .describe('JSON Schema type: string, number, boolean, object, array'),
                    required: z.boolean().describe('Whether this field is required'),
                    description: z.string().optional().describe('Field description'),
                }))
                    .describe('Payload field definitions'),
                broker: z
                    .enum(['kafka', 'rabbitmq', 'sqs-sns', 'nats', 'eventbridge', 'pubsub', 'unknown'])
                    .optional()
                    .describe('Message broker (auto-detected from project stack if omitted)'),
                specId: z.string().optional().describe('SPEC-XXX that references this contract'),
            })
                .optional()
                .describe('Input for generate-contract subcommand'),
            validateContract: z
                .object({
                projectId: z.string().describe('Project ID'),
                eventName: z.string().describe('Event name to validate against'),
                payload: z.record(z.string(), z.unknown()).describe('Payload object to validate'),
            })
                .optional()
                .describe('Input for validate-contract subcommand'),
            evolveContract: z
                .object({
                projectId: z.string().describe('Project ID'),
                eventName: z.string().describe('Event name to evolve'),
                changeDescription: z.string().describe('Human-readable description of the change'),
                addedFields: z.array(z.string()).optional().describe('New optional fields added'),
                removedFields: z.array(z.string()).optional().describe('Fields removed (breaking)'),
                changedFields: z
                    .array(z.object({
                    field: z.string(),
                    from: z.string().describe('Previous type'),
                    to: z.string().describe('New type'),
                }))
                    .optional()
                    .describe('Fields whose type changed (breaking)'),
                deprecatedFields: z
                    .array(z.object({
                    field: z.string(),
                    reason: z.string(),
                    sunsetVersion: z.string().describe('Version at which field will be removed'),
                }))
                    .optional()
                    .describe('Fields marked deprecated'),
            })
                .optional()
                .describe('Input for evolve-contract subcommand'),
            sagaSpec: z
                .object({
                projectId: z.string().describe('Project ID'),
                sagaId: z.string().describe('Unique Saga ID, e.g. "checkout-saga"'),
                description: z.string().describe('What the Saga achieves'),
                coordinationStyle: z
                    .enum(['choreography', 'orchestration'])
                    .describe('Coordination style'),
                steps: z
                    .array(z.object({
                    id: z.string().describe('Unique step ID'),
                    name: z.string().describe('Step name'),
                    service: z.string().describe('Service executing this step'),
                    successEvent: z.string().describe('Event emitted on step success'),
                    failureEvent: z.string().describe('Event emitted on step failure'),
                    compensationEvent: z
                        .string()
                        .describe('Event that compensates / undoes this step'),
                    failureConditions: z.array(z.string()).describe('Conditions causing failure'),
                    dependsOn: z.array(z.string()).describe('Step IDs that must complete first'),
                }))
                    .describe('Ordered Saga steps — each must have a compensationEvent'),
                orchestratorService: z
                    .string()
                    .optional()
                    .describe('Orchestrator service name (required if orchestration style)'),
                specId: z.string().optional().describe('SPEC-XXX implementing this Saga'),
            })
                .optional()
                .describe('Input for saga-spec subcommand'),
        },
    }, safeLicensed('event_contracts', async (args) => handleEventContracts(args)));
}
//# sourceMappingURL=register-event-tools.js.map