import { f as defineAdminEventHandler, h as requireAdminRole, c as createError, q as readBody, t as getAdminActor, u as applyAIAction } from '../../../../../../nitro/nitro.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

const apply_post = defineAdminEventHandler("admin:ai:actions:apply", async (event) => {
  var _a, _b;
  await requireAdminRole(event, ["super-admin", "admin"]);
  const publicId = (_a = event.context.params) == null ? void 0 : _a.id;
  if (typeof publicId !== "string" || publicId.length === 0) {
    throw createError({
      statusCode: 400,
      statusMessage: "Bad Request",
      message: "Action public_id is required."
    });
  }
  const body = (_b = await readBody(event)) != null ? _b : {};
  const reason = typeof body.reason === "string" ? body.reason.trim() : void 0;
  const auditLogId = typeof body.auditLogId === "number" && Number.isFinite(body.auditLogId) ? body.auditLogId : null;
  const actor = getAdminActor(event);
  try {
    const entry = await applyAIAction(publicId, {
      reviewer: { id: actor.id, name: actor.displayName },
      reason: reason && reason.length > 0 ? reason : void 0,
      auditLogId
    });
    return { success: true, data: entry };
  } catch (error) {
    const status = error.statusCode;
    if (status === 404 || status === 409) {
      throw createError({
        statusCode: status,
        statusMessage: status === 404 ? "Not Found" : "Conflict",
        message: error instanceof Error ? error.message : "Failed"
      });
    }
    throw error;
  }
});

export { apply_post as default };
//# sourceMappingURL=apply.post.mjs.map
