import { d as defineEventHandler, dE as createLocalizedError, a as getSchemaManager, G as createContentManager, dL as optionalAuth, bT as requirePermission } from '../../../nitro/nitro.mjs';
import { e as enrichMediaDeliveryRecord } from '../../../_/media-delivery.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 _id__get = defineEventHandler(async (event) => {
  var _a;
  try {
    const id = parseInt(((_a = event.context.params) == null ? void 0 : _a.id) || "0");
    if (!id || isNaN(id)) {
      throw createLocalizedError(event, {
        statusCode: 400,
        messageKey: "badRequest"
      });
    }
    const schemaManager = getSchemaManager();
    const mediaSchema = schemaManager.getSchema("media");
    if (!mediaSchema) {
      throw createLocalizedError(event, {
        statusCode: 404,
        messageKey: "mediaNotFound"
      });
    }
    const mediaManager = createContentManager("media");
    const media = await mediaManager.findOne(id);
    if (!media) {
      throw createLocalizedError(event, {
        statusCode: 404,
        messageKey: "mediaNotFound"
      });
    }
    await optionalAuth(event);
    await requirePermission(
      event.context.user,
      "media",
      "read",
      event.context.adminUser,
      event.context.apiToken
    );
    const responseMedia = await enrichMediaDeliveryRecord(media);
    return {
      success: true,
      data: responseMedia
    };
  } catch (error) {
    if (error && typeof error === "object" && "statusCode" in error) {
      throw error;
    }
    if (error instanceof Error && error.message.includes("Permission denied")) {
      throw createLocalizedError(event, {
        statusCode: 403,
        messageKey: "insufficientPermissions"
      });
    }
    if (error instanceof Error && error.message.includes("not found")) {
      throw createLocalizedError(event, {
        statusCode: 404,
        messageKey: "mediaNotFound"
      });
    }
    console.error("Get media error:", error);
    throw createLocalizedError(event, {
      statusCode: 500,
      messageKey: "internalError"
    });
  }
});

export { _id__get as default };
//# sourceMappingURL=_id_.get.mjs.map
