import { jsonFailure, jsonSuccess } from "@/modules/core/server/api";
import { requirePermission } from "@/modules/core/server/auth";
import { listHealthAdminData } from "@/modules/health/server/operations";

export async function GET(): Promise<Response> {
  const auth = await requirePermission("health:read", {
    action: "health.admin.list",
    targetType: "health",
  });

  if (!auth.success) {
    return auth.response;
  }

  const organizationId = auth.context.organization?.id;
  if (!organizationId) {
    return jsonFailure("请选择机构后查看健康数据", 400);
  }

  const data = await listHealthAdminData(organizationId);
  return jsonSuccess("健康数据已加载", { data });
}
