import type { RouteDef } from '../define'
import { type AiEventSchemas, aiRequestSchemas } from './ai'
import { appRequestSchemas } from './app'
import { type BinaryEventSchemas, binaryRequestSchemas } from './binary'
import { fileRequestSchemas } from './file'
import { fileProcessingRequestSchemas } from './fileProcessing'
import { knowledgeRequestSchemas } from './knowledge'
import { type SelectionEventSchemas, selectionRequestSchemas } from './selection'
import { webSearchRequestSchemas } from './webSearch'
import { type WindowEventSchemas, windowRequestSchemas } from './window'

/**
 * Global request registry — the single source of truth the main router parses
 * against. Each migrated domain spreads its own `*RequestSchemas` object here.
 *
 * Renderer code MUST `import type` from this module so the zod schema *values*
 * never enter the renderer bundle (see ipc-overview.md, "zod across processes").
 */
export const ipcRequestSchemas = {
  ...aiRequestSchemas,
  ...appRequestSchemas,
  ...binaryRequestSchemas,
  ...fileRequestSchemas,
  ...fileProcessingRequestSchemas,
  ...knowledgeRequestSchemas,
  ...selectionRequestSchemas,
  ...webSearchRequestSchemas,
  ...windowRequestSchemas
} satisfies Record<string, RouteDef>

export type IpcRequestSchemas = typeof ipcRequestSchemas
/** Union of all declared request routes (`never` until a domain is migrated). */
export type IpcRoute = keyof IpcRequestSchemas

/**
 * Global event registry (pure types — main is the TCB that constructs events, so
 * the renderer trusts them and never re-parses). Each migrated domain intersects
 * its own `*EventSchemas` type here.
 */
export type IpcEventSchemas = AiEventSchemas & BinaryEventSchemas & SelectionEventSchemas & WindowEventSchemas
/** Union of all declared event names (`never` until a domain is migrated). */
export type IpcEventName = keyof IpcEventSchemas
