import { Hono } from "hono";

type Todo = { id: number; title: string; done: boolean };

const app = new Hono();
const todos: Todo[] = [
  { id: 1, title: "Try GlueCron", done: false },
  { id: 2, title: "Push a commit", done: false },
];

app.get("/health", (c) => c.json({ ok: true }));
app.get("/todos", (c) => c.json(todos));

app.post("/todos", async (c) => {
  const body = await c.req.json<{ title?: string }>();
  if (!body?.title) return c.json({ error: "title required" }, 400);
  const todo: Todo = { id: todos.length + 1, title: body.title, done: false };
  todos.push(todo);
  return c.json(todo, 201);
});

export default app;
