import { d as defineEventHandler, b as getRouterParam, r as readBody, i as debug, c as createError, v as exists } from '../../../../nitro/nitro.mjs';
import { c as create } from '../../../../_/comments.service.mjs';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'stream';
import 'events';
import 'http';
import 'crypto';
import 'buffer';
import 'zlib';
import 'https';
import 'net';
import 'tls';
import 'url';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'vue-router';
import '@prisma/client';
import '@prisma/adapter-better-sqlite3';
import 'fs';
import 'path';
import 'fs/promises';
import 'child_process';
import 'node:child_process';
import 'node:url';

const comments_post = defineEventHandler(async (event) => {
  var _a;
  const id = getRouterParam(event, "id");
  const body = await readBody(event);
  debug("api", "POST /api/issues/[id]/comments", {
    id,
    author: body.author,
    contentLength: (_a = body.content) == null ? void 0 : _a.length
  });
  if (!id || !body.content) {
    debug("api", "POST /api/issues/[id]/comments - bad request", { id, hasContent: !!body.content });
    throw createError({
      statusCode: 400,
      message: "Issue ID and comment content required"
    });
  }
  const issueExists = await exists(id);
  if (!issueExists) {
    throw createError({
      statusCode: 404,
      message: `Issue not found: ${id}`
    });
  }
  const comment = await create(id, {
    content: body.content,
    author: body.author || "User"
  });
  return {
    id: comment.id,
    content: comment.content,
    author: comment.author,
    createdAt: comment.createdAt.toISOString()
  };
});

export { comments_post as default };
//# sourceMappingURL=comments.post.mjs.map
