// Component Registry Worker — 零件合約管理 HTTP endpoints
// index.ts 只做路由宣告，業務邏輯在 actions/（INV Layer 1）

import { Hono } from 'hono';
import { cors } from 'hono/cors';
import type { Bindings } from './types';
import guideRoute from './routes/guide';
import validateContractRoute from './routes/validateContract';
import componentsRoute from './routes/components';
import queryRoute from './routes/query';
import initRoute from './routes/init';
import analyticsRoute from './routes/analytics';

const app = new Hono<{ Bindings: Bindings }>();
app.use('*', cors());

// Health check
app.get('/', c => c.json({ service: 'component-registry', version: '1.0.0', status: 'ok' }));

// === Component Registry 端點 ===
app.route('/components/guide', guideRoute);
app.route('/components/validate-contract', validateContractRoute);
app.route('/components', queryRoute);      // GET /components/search, /:id, /:id/versions
app.route('/components', componentsRoute); // POST /components

// === 初始化端點（建立 tpl-component template）===
app.route('/init', initRoute);

// === 執行統計回寫（cypher-executor 執行收尾 fire-and-forget 打進來）===
app.route('/analytics', analyticsRoute); // POST /analytics/record

export default app;
