import { jsonSuccess } from "@/modules/core/server/api";
import { listAuditLogs } from "@/modules/core/server/audit";
import { requirePermission } from "@/modules/core/server/auth";

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

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

  const auditLogs = await listAuditLogs({ organizationId: auth.context.organization?.id, limit: 100 });
  return jsonSuccess("审计日志已加载", {
    auditLogs,
  });
}
