import { i as defineEventHandler, y as getRouterParam, e as createError, K as readBody, t as getProvider } from '../../../nitro/nitro.mjs';
import 'node:path';
import 'node:module';
import 'node:fs';
import 'node:os';
import 'dotenv';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:crypto';
import 'node:async_hooks';
import 'node:url';
import 'node:net';
import '@iconify/utils';
import 'consola';

const _id__patch = defineEventHandler(async (event) => {
  var _a, _b, _c;
  const id = getRouterParam(event, "id");
  if (!id) {
    throw createError({ statusCode: 400, statusMessage: "Missing task id" });
  }
  const body = (_a = await readBody(event)) != null ? _a : {};
  if (Object.prototype.hasOwnProperty.call(body, "title") || Object.prototype.hasOwnProperty.call(body, "description") || Object.prototype.hasOwnProperty.call(body, "name")) {
    throw createError({
      statusCode: 400,
      statusMessage: "Title/description edits are not supported by the provider interface."
    });
  }
  const status = typeof body.status === "string" ? body.status.trim() : "";
  const removeTags = Array.isArray(body.removeTags) ? body.removeTags.filter((t) => typeof t === "string" && t.length > 0) : [];
  const addTags = Array.isArray(body.addTags) ? body.addTags.filter((t) => typeof t === "string" && t.length > 0) : [];
  if (!status && removeTags.length === 0 && addTags.length === 0) {
    throw createError({
      statusCode: 400,
      statusMessage: "Body must include `status`, `addTags`, and/or `removeTags`. Title/description edits are not supported by the provider interface."
    });
  }
  const { provider } = getProvider(event);
  if (status) {
    await provider.updateStatus(id, status);
  }
  const removed = [];
  if (removeTags.length > 0) {
    if (typeof provider.removeTag !== "function") {
      throw createError({
        statusCode: 501,
        statusMessage: `${((_b = provider.constructor) == null ? void 0 : _b.name) || "provider"} does not support tag removal`
      });
    }
    for (const tag of removeTags) {
      await provider.removeTag(id, tag);
      removed.push(tag);
    }
  }
  const added = [];
  if (addTags.length > 0) {
    if (typeof provider.addTag !== "function") {
      throw createError({
        statusCode: 501,
        statusMessage: `${((_c = provider.constructor) == null ? void 0 : _c.name) || "provider"} does not support tag addition`
      });
    }
    for (const tag of addTags) {
      await provider.addTag(id, tag);
      added.push(tag);
    }
  }
  return {
    ok: true,
    id,
    applied: {
      ...status ? { status } : {},
      ...removed.length > 0 ? { removedTags: removed } : {},
      ...added.length > 0 ? { addedTags: added } : {}
    }
  };
});

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