import { d as defineEventHandler, b as getRouterParam, r as readBody, i as debug, c as createError, E as moveToNextColumnAndProcess, n as notifyIssueUpdate, t as notifyRefresh } 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 next_post = defineEventHandler(async (event) => {
  var _a, _b;
  const id = getRouterParam(event, "id");
  const body = await readBody(event).catch(() => null) || {};
  debug("api", "POST /api/issues/[id]/next", { id, force: body.force });
  if (!id) {
    debug("api", "POST /api/issues/[id]/next - bad request", { id });
    throw createError({
      statusCode: 400,
      message: "Issue ID required"
    });
  }
  try {
    const result = await moveToNextColumnAndProcess(id, {
      lang: body.lang || "fr",
      force: body.force || false
    });
    if (!result.success) {
      const message = result.error || "Move to next failed";
      throw createError({
        statusCode: message.includes("not found") ? 404 : 400,
        message
      });
    }
    notifyIssueUpdate(id, "moved");
    notifyRefresh();
    const issue = result.issue;
    return {
      key: issue == null ? void 0 : issue.key,
      title: issue == null ? void 0 : issue.title,
      column_slug: (_b = (_a = issue == null ? void 0 : issue.column) == null ? void 0 : _a.slug) != null ? _b : "",
      created_at: issue == null ? void 0 : issue.createdAt.toISOString(),
      updated_at: issue == null ? void 0 : issue.updatedAt.toISOString(),
      description: issue == null ? void 0 : issue.description,
      priority: issue == null ? void 0 : issue.priority,
      parent_key: issue == null ? void 0 : issue.parentKey,
      acceptance_criteria: issue == null ? void 0 : issue.acceptanceCriteria.map((c) => c.criterion),
      actionExecuted: result.actionExecuted
    };
  } catch (err) {
    const message = err instanceof Error ? err.message : "Move to next failed";
    throw createError({
      statusCode: message.includes("not found") ? 404 : 400,
      message
    });
  }
});

export { next_post as default };
//# sourceMappingURL=next.post.mjs.map
