import { Hono } from "hono";

interface Metrics {
  uptime: number;
  timestamp: string;
  memoryUsage: NodeJS.MemoryUsage;
}

export function createHealthRoutes(isReady?: () => boolean): Hono {
  const app = new Hono();
  const startTime = Date.now();

  app.get("/health", (c) => {
    if (isReady && !isReady()) {
      return c.json({ status: "warming_up", uptime: Date.now() - startTime }, 503);
    }
    return c.json({ status: "ok", uptime: Date.now() - startTime });
  });

  app.get("/metrics", (c) => {
    const metrics: Metrics = {
      uptime: Date.now() - startTime,
      timestamp: new Date().toISOString(),
      memoryUsage: process.memoryUsage(),
    };
    return c.json(metrics);
  });

  return app;
}
