import { checkDatabaseConnection } from "../../../lib/database";
import { getObjectStore } from "../../../lib/object-store";

export async function GET() {
  try {
    const database = await checkDatabaseConnection();
    return Response.json({
      status: database ? "ok" : "degraded",
      database,
      storage: getObjectStore().root,
      scheduler: process.env.ENABLE_SCHEDULER !== "false",
      timestamp: new Date().toISOString(),
    }, { status: database ? 200 : 503 });
  } catch (error) {
    return Response.json(
      {
        status: "error",
        database: false,
        error: error instanceof Error ? error.message : "health check failed",
      },
      { status: 503 },
    );
  }
}
