import { d as defineEventHandler, b as getRouterParam, r as readBody, i as debug, c as createError, l as findBySlugInActivePipeline, D as moveAndProcessIssueById, 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 move_post = defineEventHandler(async (event) => {
  var _a, _b, _c;
  const id = getRouterParam(event, "id");
  const body = await readBody(
    event
  );
  debug("api", "POST /api/issues/[id]/move", { id, column: body.column, force: body.force });
  if (!id || !body.column) {
    debug("api", "POST /api/issues/[id]/move - bad request", { id, column: body.column });
    throw createError({
      statusCode: 400,
      message: "Issue ID and target column required"
    });
  }
  const targetColumn = await findBySlugInActivePipeline(body.column);
  if (!targetColumn) {
    throw createError({
      statusCode: 404,
      message: `Column '${body.column}' not found in active pipeline`
    });
  }
  try {
    const result = await moveAndProcessIssueById(id, targetColumn.id, {
      lang: body.lang || "fr",
      force: body.force || false,
      async: (_a = body.async) != null ? _a : true
    });
    if (!result.success) {
      throw createError({
        statusCode: 400,
        message: result.error || "Move failed"
      });
    }
    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: (_c = (_b = issue == null ? void 0 : issue.column) == null ? void 0 : _b.slug) != null ? _c : "",
      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,
      processing: result.processing || false
    };
  } catch (err) {
    throw createError({
      statusCode: 400,
      message: err instanceof Error ? err.message : "Move failed"
    });
  }
});

export { move_post as default };
//# sourceMappingURL=move.post.mjs.map
