import { d as defineEventHandler, b as getRouterParam, r as readBody, c as createError, P as getLatestVersion, Q as activate } 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 activate_put = defineEventHandler(async (event) => {
  const rawName = getRouterParam(event, "name");
  const body = await readBody(event).catch(() => ({}));
  if (!rawName) {
    throw createError({
      statusCode: 400,
      message: "Pipeline name required"
    });
  }
  const name = decodeURIComponent(rawName);
  try {
    let version = body && "version" in body ? body.version : void 0;
    if (version === void 0) {
      const latestVersion = await getLatestVersion(name);
      if (latestVersion === null) {
        throw new Error(`Pipeline ${name} not found`);
      }
      version = latestVersion;
    }
    await activate(name, version);
    return { success: true };
  } catch (err) {
    throw createError({
      statusCode: 400,
      message: err instanceof Error ? err.message : "Activation failed"
    });
  }
});

export { activate_put as default };
//# sourceMappingURL=activate.put.mjs.map
