import { BOOLEAN_SCHEMA, EMPTY_OBJECT_SCHEMA, NUMBER_SCHEMA, STRING_SCHEMA, arraySchema, bodyEnvelopeSchema, listOutputSchema, methodDescriptor, objectSchema, runtimeEventId, } from './method-catalog-shared.js';
import { AUTOMATION_DELIVERY_POLICY_SCHEMA, AUTOMATION_FAILURE_POLICY_SCHEMA, AUTOMATION_HEARTBEAT_WAKE_SCHEMA, AUTOMATION_HEARTBEAT_RESULT_SCHEMA, AUTOMATION_INTEGRATION_SNAPSHOT_SCHEMA, AUTOMATION_RUNTIME_EXECUTION_INTENT_SCHEMA, AUTOMATION_SCHEDULE_SCHEMA, AUTOMATION_SESSION_TARGET_SCHEMA, AUTOMATION_JOB_SCHEMA, AUTOMATION_JOBS_OUTPUT_SCHEMA, AUTOMATION_RUN_ACTION_OUTPUT_SCHEMA, AUTOMATION_RUN_DETAIL_OUTPUT_SCHEMA, AUTOMATION_RUN_TRIGGER_OUTPUT_SCHEMA, AUTOMATION_RUNS_OUTPUT_SCHEMA, DELIVERY_OUTPUT_SCHEMA, DELIVERY_SNAPSHOT_SCHEMA, LEGACY_SCHEDULES_OUTPUT_SCHEMA, REMOVE_WITH_ID_OUTPUT_SCHEMA, ROUTE_BINDING_SCHEMA, ROUTE_SNAPSHOT_SCHEMA, SURFACE_RECORD_SCHEMA, } from './operator-contract-schemas.js';
import { METADATA_SCHEMA } from './operator-contract-schemas-shared.js';
export const builtinGatewayControlAutomationMethodDescriptors = [
    methodDescriptor({
        id: 'automation.integration.snapshot',
        title: 'Automation Integration Snapshot',
        description: 'Return the legacy integration automation snapshot.',
        category: 'automation',
        scopes: ['read:automation'],
        http: { method: 'GET', path: '/api/automation' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: AUTOMATION_INTEGRATION_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.jobs.list',
        title: 'List Automation Jobs',
        description: 'Return automation jobs and recent runs.',
        category: 'automation',
        scopes: ['read:automation'],
        http: { method: 'GET', path: '/api/automation/jobs' },
        events: [runtimeEventId('automation')],
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: AUTOMATION_JOBS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.jobs.create',
        title: 'Create Automation Job',
        description: 'Create a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/jobs' },
        events: [runtimeEventId('automation')],
        inputSchema: bodyEnvelopeSchema({
            id: STRING_SCHEMA,
            name: STRING_SCHEMA,
            description: STRING_SCHEMA,
            prompt: STRING_SCHEMA,
            kind: STRING_SCHEMA,
            cron: STRING_SCHEMA,
            every: STRING_SCHEMA,
            at: STRING_SCHEMA,
            timezone: STRING_SCHEMA,
            staggerMs: NUMBER_SCHEMA,
            model: STRING_SCHEMA,
            provider: STRING_SCHEMA,
            fallbackModels: arraySchema(STRING_SCHEMA),
            executionIntent: AUTOMATION_RUNTIME_EXECUTION_INTENT_SCHEMA,
            template: STRING_SCHEMA,
            target: AUTOMATION_SESSION_TARGET_SCHEMA,
            reasoningEffort: STRING_SCHEMA,
            thinking: STRING_SCHEMA,
            wakeMode: STRING_SCHEMA,
            timeoutMs: NUMBER_SCHEMA,
            toolAllowlist: arraySchema(STRING_SCHEMA),
            autoApprove: BOOLEAN_SCHEMA,
            allowUnsafeExternalContent: BOOLEAN_SCHEMA,
            externalContentSource: STRING_SCHEMA,
            lightContext: BOOLEAN_SCHEMA,
            delivery: AUTOMATION_DELIVERY_POLICY_SCHEMA,
            failure: AUTOMATION_FAILURE_POLICY_SCHEMA,
            enabled: BOOLEAN_SCHEMA,
            deleteAfterRun: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['prompt']),
        outputSchema: AUTOMATION_JOB_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.jobs.patch',
        title: 'Patch Automation Job',
        description: 'Patch a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'PATCH', path: '/api/automation/jobs/{jobId}' },
        events: [runtimeEventId('automation')],
        inputSchema: bodyEnvelopeSchema({
            jobId: STRING_SCHEMA,
            name: STRING_SCHEMA,
            description: STRING_SCHEMA,
            prompt: STRING_SCHEMA,
            schedule: AUTOMATION_SCHEDULE_SCHEMA,
            model: STRING_SCHEMA,
            provider: STRING_SCHEMA,
            fallbackModels: arraySchema(STRING_SCHEMA),
            executionIntent: AUTOMATION_RUNTIME_EXECUTION_INTENT_SCHEMA,
            template: STRING_SCHEMA,
            target: AUTOMATION_SESSION_TARGET_SCHEMA,
            reasoningEffort: STRING_SCHEMA,
            thinking: STRING_SCHEMA,
            wakeMode: STRING_SCHEMA,
            timeoutMs: NUMBER_SCHEMA,
            toolAllowlist: arraySchema(STRING_SCHEMA),
            autoApprove: BOOLEAN_SCHEMA,
            allowUnsafeExternalContent: BOOLEAN_SCHEMA,
            externalContentSource: STRING_SCHEMA,
            lightContext: BOOLEAN_SCHEMA,
            delivery: AUTOMATION_DELIVERY_POLICY_SCHEMA,
            failure: AUTOMATION_FAILURE_POLICY_SCHEMA,
            enabled: BOOLEAN_SCHEMA,
            deleteAfterRun: BOOLEAN_SCHEMA,
            metadata: METADATA_SCHEMA,
        }),
        outputSchema: AUTOMATION_JOB_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.jobs.delete',
        title: 'Delete Automation Job',
        description: 'Delete a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'DELETE', path: '/api/automation/jobs/{jobId}' },
        events: [runtimeEventId('automation')],
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: REMOVE_WITH_ID_OUTPUT_SCHEMA,
        dangerous: true,
    }),
    methodDescriptor({
        id: 'automation.jobs.enable',
        title: 'Enable Automation Job',
        description: 'Enable a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/jobs/{jobId}/enable' },
        events: [runtimeEventId('automation')],
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: objectSchema({ id: STRING_SCHEMA, enabled: BOOLEAN_SCHEMA }, ['id', 'enabled'], { additionalProperties: true }),
    }),
    methodDescriptor({
        id: 'automation.jobs.disable',
        title: 'Disable Automation Job',
        description: 'Disable a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/jobs/{jobId}/disable' },
        events: [runtimeEventId('automation')],
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: objectSchema({ id: STRING_SCHEMA, enabled: BOOLEAN_SCHEMA }, ['id', 'enabled'], { additionalProperties: true }),
    }),
    methodDescriptor({
        id: 'automation.jobs.pause',
        title: 'Pause Automation Job',
        description: 'Pause a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/jobs/{jobId}/pause' },
        events: [runtimeEventId('automation')],
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: objectSchema({ id: STRING_SCHEMA, enabled: BOOLEAN_SCHEMA }, ['id', 'enabled'], { additionalProperties: true }),
    }),
    methodDescriptor({
        id: 'automation.jobs.resume',
        title: 'Resume Automation Job',
        description: 'Resume a durable automation job.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/jobs/{jobId}/resume' },
        events: [runtimeEventId('automation')],
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: objectSchema({ id: STRING_SCHEMA, enabled: BOOLEAN_SCHEMA }, ['id', 'enabled'], { additionalProperties: true }),
    }),
    methodDescriptor({
        id: 'automation.jobs.run',
        title: 'Run Automation Job Now',
        description: 'Trigger an automation job immediately.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/jobs/{jobId}/run' },
        events: [runtimeEventId('automation')],
        inputSchema: objectSchema({ jobId: STRING_SCHEMA }, ['jobId']),
        outputSchema: AUTOMATION_RUN_TRIGGER_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.runs.list',
        title: 'List Automation Runs',
        description: 'Return automation run history.',
        category: 'automation',
        scopes: ['read:automation'],
        http: { method: 'GET', path: '/api/automation/runs' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: AUTOMATION_RUNS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.runs.get',
        title: 'Get Automation Run',
        description: 'Return a single automation run record.',
        category: 'automation',
        scopes: ['read:automation'],
        http: { method: 'GET', path: '/api/automation/runs/{runId}' },
        inputSchema: objectSchema({ runId: STRING_SCHEMA }, ['runId']),
        outputSchema: AUTOMATION_RUN_DETAIL_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.runs.cancel',
        title: 'Cancel Automation Run',
        description: 'Cancel an active automation run.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/runs/{runId}/cancel' },
        inputSchema: objectSchema({ runId: STRING_SCHEMA }, ['runId']),
        outputSchema: AUTOMATION_RUN_ACTION_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.runs.retry',
        title: 'Retry Automation Run',
        description: 'Retry a completed or failed automation run.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/runs/{runId}/retry' },
        inputSchema: objectSchema({ runId: STRING_SCHEMA }, ['runId']),
        outputSchema: AUTOMATION_RUN_ACTION_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'automation.heartbeat.list',
        title: 'List Automation Heartbeat Queue',
        description: 'Return automation jobs queued for the next heartbeat.',
        category: 'automation',
        scopes: ['read:automation'],
        http: { method: 'GET', path: '/api/automation/heartbeat' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: objectSchema({ pending: arraySchema(AUTOMATION_HEARTBEAT_WAKE_SCHEMA) }, ['pending']),
    }),
    methodDescriptor({
        id: 'automation.heartbeat.run',
        title: 'Run Automation Heartbeat',
        description: 'Process automation jobs queued for the next heartbeat.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/api/automation/heartbeat' },
        events: [runtimeEventId('automation')],
        inputSchema: bodyEnvelopeSchema({ source: STRING_SCHEMA }),
        outputSchema: AUTOMATION_HEARTBEAT_RESULT_SCHEMA,
    }),
    methodDescriptor({
        id: 'deliveries.list',
        title: 'List Deliveries',
        description: 'Return delivery records and integration snapshot data.',
        category: 'deliveries',
        scopes: ['read:deliveries'],
        http: { method: 'GET', path: '/api/deliveries' },
        events: [runtimeEventId('deliveries')],
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: DELIVERY_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'deliveries.get',
        title: 'Get Delivery',
        description: 'Return a single delivery record.',
        category: 'deliveries',
        scopes: ['read:deliveries'],
        http: { method: 'GET', path: '/api/deliveries/{deliveryId}' },
        inputSchema: objectSchema({ deliveryId: STRING_SCHEMA }, ['deliveryId']),
        outputSchema: DELIVERY_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'schedules.list',
        title: 'List Schedules',
        description: 'Return legacy schedule records.',
        category: 'automation',
        scopes: ['read:automation'],
        http: { method: 'GET', path: '/schedules' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: LEGACY_SCHEDULES_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'schedules.create',
        title: 'Create Schedule',
        description: 'Create a legacy schedule record.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/schedules' },
        inputSchema: bodyEnvelopeSchema({
            name: STRING_SCHEMA,
            prompt: STRING_SCHEMA,
            kind: STRING_SCHEMA,
            cron: STRING_SCHEMA,
            every: STRING_SCHEMA,
            at: STRING_SCHEMA,
            timezone: STRING_SCHEMA,
            staggerMs: NUMBER_SCHEMA,
            model: STRING_SCHEMA,
            provider: STRING_SCHEMA,
            fallbackModels: arraySchema(STRING_SCHEMA),
            template: STRING_SCHEMA,
            target: AUTOMATION_SESSION_TARGET_SCHEMA,
            reasoningEffort: STRING_SCHEMA,
            thinking: STRING_SCHEMA,
            wakeMode: STRING_SCHEMA,
            timeoutMs: NUMBER_SCHEMA,
            toolAllowlist: arraySchema(STRING_SCHEMA),
            autoApprove: BOOLEAN_SCHEMA,
            allowUnsafeExternalContent: BOOLEAN_SCHEMA,
            externalContentSource: STRING_SCHEMA,
            lightContext: BOOLEAN_SCHEMA,
            delivery: AUTOMATION_DELIVERY_POLICY_SCHEMA,
            failure: AUTOMATION_FAILURE_POLICY_SCHEMA,
            enabled: BOOLEAN_SCHEMA,
            deleteAfterRun: BOOLEAN_SCHEMA,
        }, ['prompt']),
        outputSchema: AUTOMATION_JOB_SCHEMA,
    }),
    methodDescriptor({
        id: 'schedules.delete',
        title: 'Delete Schedule',
        description: 'Delete a legacy schedule record.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'DELETE', path: '/schedules/{scheduleId}' },
        inputSchema: objectSchema({ scheduleId: STRING_SCHEMA }, ['scheduleId']),
        outputSchema: REMOVE_WITH_ID_OUTPUT_SCHEMA,
        dangerous: true,
    }),
    methodDescriptor({
        id: 'schedules.enable',
        title: 'Enable Schedule',
        description: 'Enable a legacy schedule record.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/schedules/{scheduleId}/enable' },
        inputSchema: objectSchema({ scheduleId: STRING_SCHEMA }, ['scheduleId']),
        outputSchema: objectSchema({ id: STRING_SCHEMA, enabled: BOOLEAN_SCHEMA }, ['id', 'enabled'], { additionalProperties: true }),
    }),
    methodDescriptor({
        id: 'schedules.disable',
        title: 'Disable Schedule',
        description: 'Disable a legacy schedule record.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/schedules/{scheduleId}/disable' },
        inputSchema: objectSchema({ scheduleId: STRING_SCHEMA }, ['scheduleId']),
        outputSchema: objectSchema({ id: STRING_SCHEMA, enabled: BOOLEAN_SCHEMA }, ['id', 'enabled'], { additionalProperties: true }),
    }),
    methodDescriptor({
        id: 'schedules.run',
        title: 'Run Schedule Now',
        description: 'Trigger a legacy schedule immediately.',
        category: 'automation',
        scopes: ['write:automation'],
        http: { method: 'POST', path: '/schedules/{scheduleId}/run' },
        inputSchema: objectSchema({ scheduleId: STRING_SCHEMA }, ['scheduleId']),
        outputSchema: AUTOMATION_RUN_TRIGGER_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'routes.snapshot',
        title: 'Route Snapshot',
        description: 'Return the route and binding integration snapshot.',
        category: 'routes',
        scopes: ['read:routes'],
        http: { method: 'GET', path: '/api/routes' },
        events: [runtimeEventId('routes')],
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: ROUTE_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'surfaces.list',
        title: 'List Surfaces',
        description: 'Return registered channel and control surfaces.',
        category: 'routes',
        scopes: ['read:routes'],
        http: { method: 'GET', path: '/api/surfaces' },
        events: [runtimeEventId('surfaces')],
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: listOutputSchema('surfaces', SURFACE_RECORD_SCHEMA),
    }),
    methodDescriptor({
        id: 'routes.bindings.list',
        title: 'List Route Bindings',
        description: 'Return configured route bindings.',
        category: 'routes',
        scopes: ['read:routes'],
        http: { method: 'GET', path: '/api/routes/bindings' },
        events: [runtimeEventId('routes')],
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: listOutputSchema('bindings', ROUTE_BINDING_SCHEMA),
    }),
    methodDescriptor({
        id: 'routes.bindings.create',
        title: 'Create Route Binding',
        description: 'Create or upsert a route binding.',
        category: 'routes',
        scopes: ['write:routes'],
        access: 'admin',
        http: { method: 'POST', path: '/api/routes/bindings' },
        events: [runtimeEventId('routes')],
        inputSchema: bodyEnvelopeSchema({
            id: STRING_SCHEMA,
            kind: STRING_SCHEMA,
            surfaceKind: STRING_SCHEMA,
            surfaceId: STRING_SCHEMA,
            externalId: STRING_SCHEMA,
            sessionPolicy: STRING_SCHEMA,
            threadPolicy: STRING_SCHEMA,
            deliveryGuarantee: STRING_SCHEMA,
            threadId: STRING_SCHEMA,
            channelId: STRING_SCHEMA,
            sessionId: STRING_SCHEMA,
            jobId: STRING_SCHEMA,
            runId: STRING_SCHEMA,
            title: STRING_SCHEMA,
            metadata: METADATA_SCHEMA,
        }, ['kind', 'surfaceKind', 'surfaceId', 'externalId']),
        outputSchema: ROUTE_BINDING_SCHEMA,
    }),
    methodDescriptor({
        id: 'routes.bindings.patch',
        title: 'Patch Route Binding',
        description: 'Patch an existing route binding.',
        category: 'routes',
        scopes: ['write:routes'],
        access: 'admin',
        http: { method: 'PATCH', path: '/api/routes/bindings/{bindingId}' },
        events: [runtimeEventId('routes')],
        inputSchema: bodyEnvelopeSchema({
            bindingId: STRING_SCHEMA,
            sessionPolicy: STRING_SCHEMA,
            threadPolicy: STRING_SCHEMA,
            deliveryGuarantee: STRING_SCHEMA,
            threadId: STRING_SCHEMA,
            channelId: STRING_SCHEMA,
            sessionId: STRING_SCHEMA,
            jobId: STRING_SCHEMA,
            runId: STRING_SCHEMA,
            title: STRING_SCHEMA,
            metadata: METADATA_SCHEMA,
        }),
        outputSchema: ROUTE_BINDING_SCHEMA,
    }),
    methodDescriptor({
        id: 'routes.bindings.delete',
        title: 'Delete Route Binding',
        description: 'Delete an existing route binding.',
        category: 'routes',
        scopes: ['write:routes'],
        access: 'admin',
        http: { method: 'DELETE', path: '/api/routes/bindings/{bindingId}' },
        events: [runtimeEventId('routes')],
        inputSchema: objectSchema({ bindingId: STRING_SCHEMA }, ['bindingId']),
        outputSchema: REMOVE_WITH_ID_OUTPUT_SCHEMA,
        dangerous: true,
    }),
];
