// POST /init — 確保 tpl-component template 存在（冪等）
// Requirements: 12.1

import { Hono } from 'hono';
import type { Bindings } from '../types';
import { ensureTemplate } from '../actions/ensureTemplate';

const app = new Hono<{ Bindings: Bindings }>();

app.post('/', async c => {
  try {
    const result = await ensureTemplate(c.env);
    return c.json({ success: true, ...result });
  } catch (err) {
    const message = err instanceof Error ? err.message : String(err);
    return c.json({ success: false, error: message }, 500);
  }
});

export default app;
