import { EMPTY_OBJECT_SCHEMA, STRING_SCHEMA, objectSchema, listOutputSchema, entityOutputSchema, bodyEnvelopeSchema, methodDescriptor, runtimeEventId, } from './method-catalog-shared.js';
import { CONTINUITY_SNAPSHOT_SCHEMA, DISTRIBUTED_NODE_HOST_CONTRACT_SCHEMA, HEALTH_SNAPSHOT_SCHEMA, INTELLIGENCE_SNAPSHOT_SCHEMA, MEMORY_DOCTOR_REPORT_SCHEMA, MEMORY_VECTOR_STATS_SCHEMA, PROVIDER_ACCOUNT_SNAPSHOT_SCHEMA, PROVIDER_RUNTIME_SNAPSHOT_SCHEMA, PROVIDER_USAGE_SNAPSHOT_SCHEMA, REMOTE_PAIR_APPROVAL_OUTPUT_SCHEMA, REMOTE_PAIR_REQUEST_OUTPUT_SCHEMA, REMOTE_PAIR_REQUESTS_OUTPUT_SCHEMA, REMOTE_PEERS_OUTPUT_SCHEMA, REMOTE_PAIR_REQUEST_ACTION_INPUT_SCHEMA, REMOTE_PEER_DISCONNECT_INPUT_SCHEMA, REMOTE_PEER_INVOKE_INPUT_SCHEMA, REMOTE_PEER_INVOKE_OUTPUT_SCHEMA, REMOTE_PEER_OUTPUT_SCHEMA, REMOTE_PEER_TOKEN_REVOKE_INPUT_SCHEMA, REMOTE_PEER_TOKEN_ROTATE_INPUT_SCHEMA, REMOTE_PEER_TOKEN_ROTATE_OUTPUT_SCHEMA, REMOTE_SNAPSHOT_SCHEMA, REMOTE_WORK_LIST_OUTPUT_SCHEMA, REMOTE_WORK_CANCEL_INPUT_SCHEMA, REMOTE_WORK_OUTPUT_SCHEMA, SETTINGS_SNAPSHOT_SCHEMA, WORKTREE_SNAPSHOT_SCHEMA, } from './operator-contract-schemas.js';
export const builtinGatewayRuntimeMethodDescriptors = [
    methodDescriptor({
        id: 'remote.snapshot',
        title: 'Remote Runtime Snapshot',
        description: 'Return distributed node/device runtime state.',
        category: 'remote',
        scopes: ['read:remote'],
        http: { method: 'GET', path: '/api/remote' },
        events: [runtimeEventId('control-plane')],
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: REMOTE_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.pair.requests.list',
        title: 'List Remote Pair Requests',
        description: 'Return pending remote pair requests.',
        category: 'remote',
        scopes: ['read:remote'],
        http: { method: 'GET', path: '/api/remote/pair/requests' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: REMOTE_PAIR_REQUESTS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.pair.requests.approve',
        title: 'Approve Remote Pair Request',
        description: 'Approve a pending remote pair request.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/pair/requests/{requestId}/approve' },
        inputSchema: REMOTE_PAIR_REQUEST_ACTION_INPUT_SCHEMA,
        outputSchema: REMOTE_PAIR_APPROVAL_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.pair.requests.reject',
        title: 'Reject Remote Pair Request',
        description: 'Reject a pending remote pair request.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/pair/requests/{requestId}/reject' },
        inputSchema: REMOTE_PAIR_REQUEST_ACTION_INPUT_SCHEMA,
        outputSchema: REMOTE_PAIR_REQUEST_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.peers.list',
        title: 'List Remote Peers',
        description: 'Return known remote peers.',
        category: 'remote',
        scopes: ['read:remote'],
        http: { method: 'GET', path: '/api/remote/peers' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: REMOTE_PEERS_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.peers.token.rotate',
        title: 'Rotate Remote Peer Token',
        description: 'Rotate the active token for a remote peer.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/peers/{peerId}/token/rotate' },
        inputSchema: REMOTE_PEER_TOKEN_ROTATE_INPUT_SCHEMA,
        outputSchema: REMOTE_PEER_TOKEN_ROTATE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.peers.token.revoke',
        title: 'Revoke Remote Peer Token',
        description: 'Revoke the active token for a remote peer.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/peers/{peerId}/token/revoke' },
        inputSchema: REMOTE_PEER_TOKEN_REVOKE_INPUT_SCHEMA,
        outputSchema: REMOTE_PEER_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.peers.disconnect',
        title: 'Disconnect Remote Peer',
        description: 'Disconnect a remote peer.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/peers/{peerId}/disconnect' },
        inputSchema: REMOTE_PEER_DISCONNECT_INPUT_SCHEMA,
        outputSchema: REMOTE_PEER_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.peers.invoke',
        title: 'Invoke Remote Peer',
        description: 'Invoke a method on a connected remote peer.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/peers/{peerId}/invoke' },
        inputSchema: REMOTE_PEER_INVOKE_INPUT_SCHEMA,
        outputSchema: REMOTE_PEER_INVOKE_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.work.list',
        title: 'List Remote Work',
        description: 'Return queued and leased remote work items.',
        category: 'remote',
        scopes: ['read:remote'],
        http: { method: 'GET', path: '/api/remote/work' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: REMOTE_WORK_LIST_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.work.cancel',
        title: 'Cancel Remote Work',
        description: 'Cancel a remote work item.',
        category: 'remote',
        scopes: ['write:remote'],
        access: 'admin',
        http: { method: 'POST', path: '/api/remote/work/{workId}/cancel' },
        inputSchema: REMOTE_WORK_CANCEL_INPUT_SCHEMA,
        outputSchema: REMOTE_WORK_OUTPUT_SCHEMA,
    }),
    methodDescriptor({
        id: 'remote.node_host.contract',
        title: 'Node Host Contract',
        description: 'Return the distributed node/device host API contract.',
        category: 'remote',
        scopes: ['read:remote'],
        http: { method: 'GET', path: '/api/remote/node-host/contract' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: entityOutputSchema('contract', DISTRIBUTED_NODE_HOST_CONTRACT_SCHEMA),
        metadata: { aliasPaths: ['/api/remote/device/contract'] },
    }),
    methodDescriptor({
        id: 'health.snapshot',
        title: 'Health Snapshot',
        description: 'Return the health integration snapshot.',
        category: 'health',
        scopes: ['read:health'],
        http: { method: 'GET', path: '/api/health' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: HEALTH_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'accounts.snapshot',
        title: 'Accounts Snapshot',
        description: 'Return provider and channel account posture.',
        category: 'accounts',
        scopes: ['read:accounts'],
        http: { method: 'GET', path: '/api/accounts' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: PROVIDER_ACCOUNT_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'providers.list',
        title: 'Providers List',
        description: 'Return runtime provider metadata, policy hooks, and priced model summaries.',
        category: 'providers',
        scopes: ['read:providers'],
        http: { method: 'GET', path: '/api/providers' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: listOutputSchema('providers', PROVIDER_RUNTIME_SNAPSHOT_SCHEMA),
    }),
    methodDescriptor({
        id: 'providers.get',
        title: 'Provider Snapshot',
        description: 'Return runtime metadata for a single provider.',
        category: 'providers',
        scopes: ['read:providers'],
        http: { method: 'GET', path: '/api/providers/{providerId}' },
        inputSchema: objectSchema({ providerId: STRING_SCHEMA }, ['providerId']),
        outputSchema: PROVIDER_RUNTIME_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'providers.usage.get',
        title: 'Provider Usage',
        description: 'Return usage and pricing posture for a single provider.',
        category: 'providers',
        scopes: ['read:providers'],
        http: { method: 'GET', path: '/api/providers/{providerId}/usage' },
        inputSchema: objectSchema({ providerId: STRING_SCHEMA }, ['providerId']),
        outputSchema: PROVIDER_USAGE_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'settings.snapshot',
        title: 'Settings Snapshot',
        description: 'Return the settings integration snapshot.',
        category: 'settings',
        scopes: ['read:settings'],
        http: { method: 'GET', path: '/api/settings' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: SETTINGS_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'continuity.snapshot',
        title: 'Continuity Snapshot',
        description: 'Return the continuity integration snapshot.',
        category: 'continuity',
        scopes: ['read:continuity'],
        http: { method: 'GET', path: '/api/continuity' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: CONTINUITY_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'worktrees.snapshot',
        title: 'Worktrees Snapshot',
        description: 'Return the worktree integration snapshot.',
        category: 'worktrees',
        scopes: ['read:worktrees'],
        http: { method: 'GET', path: '/api/worktrees' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: WORKTREE_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'intelligence.snapshot',
        title: 'Intelligence Snapshot',
        description: 'Return the intelligence integration snapshot.',
        category: 'intelligence',
        scopes: ['read:intelligence'],
        http: { method: 'GET', path: '/api/intelligence' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: INTELLIGENCE_SNAPSHOT_SCHEMA,
    }),
    methodDescriptor({
        id: 'memory.doctor',
        title: 'Memory Doctor',
        description: 'Return sqlite-vec and memory embedding-provider diagnostics.',
        category: 'memory',
        scopes: ['read:memory'],
        http: { method: 'GET', path: '/api/memory/doctor' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: MEMORY_DOCTOR_REPORT_SCHEMA,
    }),
    methodDescriptor({
        id: 'memory.vector.stats',
        title: 'Memory Vector Stats',
        description: 'Return the current sqlite-vec vector-store posture.',
        category: 'memory',
        scopes: ['read:memory'],
        http: { method: 'GET', path: '/api/memory/vector' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: objectSchema({ vector: MEMORY_VECTOR_STATS_SCHEMA }, ['vector']),
    }),
    methodDescriptor({
        id: 'memory.vector.rebuild',
        title: 'Rebuild Memory Vector Index',
        description: 'Rebuild the sqlite-vec vector index.',
        category: 'memory',
        scopes: ['write:memory'],
        access: 'admin',
        http: { method: 'POST', path: '/api/memory/vector/rebuild' },
        inputSchema: EMPTY_OBJECT_SCHEMA,
        outputSchema: objectSchema({ vector: MEMORY_VECTOR_STATS_SCHEMA }, ['vector']),
    }),
    methodDescriptor({
        id: 'memory.embeddings.default.set',
        title: 'Set Default Memory Embedding Provider',
        description: 'Set the active default memory embedding provider.',
        category: 'memory',
        scopes: ['write:memory'],
        access: 'admin',
        http: { method: 'POST', path: '/api/memory/embeddings/default' },
        inputSchema: bodyEnvelopeSchema({ providerId: STRING_SCHEMA }, ['providerId']),
        outputSchema: MEMORY_DOCTOR_REPORT_SCHEMA,
    }),
];
