import { d as defineEventHandler, b as getRouterParam, r as readBody, i as debug, c as createError, k as update, n as notifyIssueUpdate } from '../../../nitro/nitro.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 _id__patch = defineEventHandler(async (event) => {
  var _a, _b;
  const id = getRouterParam(event, "id");
  const body = await readBody(event);
  debug("api", "PATCH /api/issues/[id]", { id, fields: Object.keys(body) });
  if (!id) {
    debug("api", "PATCH /api/issues/[id] - bad request", { id });
    throw createError({
      statusCode: 400,
      message: "Issue ID required"
    });
  }
  try {
    const issue = await update(id, {
      ...body.title !== void 0 ? { title: body.title } : {},
      ...body.description !== void 0 ? { description: body.description } : {},
      ...body.priority !== void 0 ? { priority: body.priority } : {},
      ...body.parent_key !== void 0 ? { parentKey: body.parent_key } : {},
      ...body.acceptance_criteria !== void 0 ? { acceptanceCriteria: body.acceptance_criteria } : {}
    });
    notifyIssueUpdate(id, "updated");
    return {
      key: issue.key,
      title: issue.title,
      column_slug: (_b = (_a = issue.column) == null ? void 0 : _a.slug) != null ? _b : "",
      created_at: issue.createdAt.toISOString(),
      updated_at: issue.updatedAt.toISOString(),
      description: issue.description,
      priority: issue.priority,
      parent_key: issue.parentKey,
      acceptance_criteria: issue.acceptanceCriteria.map((c) => c.criterion)
    };
  } catch (err) {
    throw createError({
      statusCode: 404,
      message: err instanceof Error ? err.message : "Update failed"
    });
  }
});

export { _id__patch as default };
//# sourceMappingURL=_id_.patch.mjs.map
