/**
 * tRPC Router — Merge Point
 *
 * Combines all domain routers into a single application router.
 * Each domain file exports a builder function that returns procedure records.
 */

import { router, publicProcedure } from './trpc.js';
import { systemProcedures } from './routers/system.js';
import { agentProcedures } from './routers/agent.js';
import { taskProcedures } from './routers/task.js';
import { messageProcedures } from './routers/message.js';
import { dispatchProcedures } from './routers/dispatch.js';
import { coordinationProcedures } from './routers/coordination.js';
import { initiativeProcedures } from './routers/initiative.js';
import { phaseProcedures } from './routers/phase.js';
import { phaseDispatchProcedures } from './routers/phase-dispatch.js';
import { architectProcedures } from './routers/architect.js';
import { projectProcedures } from './routers/project.js';
import { pageProcedures } from './routers/page.js';
import { accountProcedures } from './routers/account.js';
import { changeSetProcedures } from './routers/change-set.js';
import { subscriptionProcedures } from './routers/subscription.js';
import { previewProcedures } from './routers/preview.js';
import { conversationProcedures } from './routers/conversation.js';
import { chatSessionProcedures } from './routers/chat-session.js';
import { errandProcedures } from './routers/errand.js';

// Re-export tRPC primitives (preserves existing import paths)
export { router, publicProcedure, middleware, createCallerFactory } from './trpc.js';

// Re-export schemas and types from domain routers
export {
  healthResponseSchema,
  processInfoSchema,
  statusResponseSchema,
} from './routers/system.js';
export type { HealthResponse, StatusResponse, ProcessInfo } from './routers/system.js';

export {
  spawnAgentInputSchema,
  agentIdentifierSchema,
  resumeAgentInputSchema,
} from './routers/agent.js';
export type { SpawnAgentInput, AgentIdentifier, ResumeAgentInput } from './routers/agent.js';

// Application router
export const appRouter = router({
  ...systemProcedures(publicProcedure),
  ...agentProcedures(publicProcedure),
  ...taskProcedures(publicProcedure),
  ...messageProcedures(publicProcedure),
  ...dispatchProcedures(publicProcedure),
  ...coordinationProcedures(publicProcedure),
  ...initiativeProcedures(publicProcedure),
  ...phaseProcedures(publicProcedure),
  ...phaseDispatchProcedures(publicProcedure),
  ...architectProcedures(publicProcedure),
  ...projectProcedures(publicProcedure),
  ...pageProcedures(publicProcedure),
  ...accountProcedures(publicProcedure),
  ...changeSetProcedures(publicProcedure),
  ...subscriptionProcedures(publicProcedure),
  ...previewProcedures(publicProcedure),
  ...conversationProcedures(publicProcedure),
  ...chatSessionProcedures(publicProcedure),
  ...errandProcedures(publicProcedure),
});

export type AppRouter = typeof appRouter;
