import { Router } from 'express';

/** GET /api/v1/health — DB ping for uptime monitoring. 503 when the database is unreachable. */
export function healthRouter(ping: () => Promise<boolean>) {
  const r = Router();
  r.get('/health', async (_req, res) => {
    const up = await ping();
    res.set('Cache-Control', 'no-store');
    res.status(up ? 200 : 503).json({ ok: up, db: up ? 'up' : 'down', uptime: Math.round(process.uptime()) });
  });
  return r;
}
