import { d as defineEventHandler, r as readBody, c as createError, U as create } 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 index_post = defineEventHandler(async (event) => {
  var _a;
  const body = await readBody(event);
  if (!((_a = body.name) == null ? void 0 : _a.trim())) {
    throw createError({
      statusCode: 400,
      message: "Pipeline name required"
    });
  }
  try {
    const pipeline = await create({
      name: body.name,
      ...body.description ? { description: body.description } : {},
      ...body.definition ? { definition: body.definition } : {},
      ...body.action ? { action: body.action } : {},
      ...body.finish ? { finish: body.finish } : {}
    });
    return {
      name: pipeline.name,
      version: pipeline.version,
      description: pipeline.description,
      active: pipeline.active,
      definition: pipeline.columns.filter((c) => c.segment === "definition").map((c) => ({ slug: c.slug, name: c.name })),
      action: pipeline.columns.filter((c) => c.segment === "action").map((c) => ({ slug: c.slug, name: c.name })),
      finish: pipeline.columns.filter((c) => c.segment === "finish").map((c) => ({ slug: c.slug, name: c.name }))
    };
  } catch (err) {
    throw createError({
      statusCode: 400,
      message: err instanceof Error ? err.message : "Create failed"
    });
  }
});

export { index_post as default };
//# sourceMappingURL=index.post3.mjs.map
