import { f as defineAdminEventHandler, aA as requireSuperAdmin, c as createError, di as listIdentitiesForUser, dj as deleteIdentity } 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 _identityId__delete = defineAdminEventHandler("admin:users:identities:unlink", async (event) => {
  var _a, _b;
  try {
    await requireSuperAdmin(event);
    const userId = Number((_a = event.context.params) == null ? void 0 : _a.id);
    const identityId = Number((_b = event.context.params) == null ? void 0 : _b.identityId);
    if (!Number.isInteger(userId) || userId <= 0) {
      throw createError({
        statusCode: 400,
        statusMessage: "Bad Request",
        message: "Invalid user id"
      });
    }
    if (!Number.isInteger(identityId) || identityId <= 0) {
      throw createError({
        statusCode: 400,
        statusMessage: "Bad Request",
        message: "Invalid identity id"
      });
    }
    const identities = await listIdentitiesForUser(userId);
    const target = identities.find((i) => i.id === identityId);
    if (!target) {
      throw createError({
        statusCode: 404,
        statusMessage: "Not Found",
        message: "Identity not found for this user"
      });
    }
    await deleteIdentity(identityId);
    return { success: true };
  } catch (error) {
    if (error && typeof error === "object" && "statusCode" in error) {
      throw error;
    }
    console.error("[DELETE /api/admin/users/:id/identities/:identityId] Error:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Failed to unlink identity",
      message: error instanceof Error ? error.message : "Unknown error"
    });
  }
});

export { _identityId__delete as default };
//# sourceMappingURL=_identityId_.delete.mjs.map
