"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var plugin_body_exports = {};
__export(plugin_body_exports, {
  prepareCreatePluginBody: () => prepareCreatePluginBody,
  prepareUpdatePluginBody: () => prepareUpdatePluginBody
});
module.exports = __toCommonJS(plugin_body_exports);
var utils = __toESM(require("../utils"));
const prepareCreatePluginBody = async (plugin) => ({
  name: plugin.name,
  version: plugin.version,
  title: "title" in plugin ? plugin.title : void 0,
  description: "description" in plugin ? plugin.description : void 0,
  user: {
    tags: plugin.user?.tags ?? {}
  },
  conversation: {
    tags: plugin.conversation?.tags ?? {}
  },
  configuration: plugin.configuration ? {
    ...plugin.configuration,
    schema: await utils.schema.mapZodToJsonSchema(plugin.configuration, {
      useLegacyZuiTransformer: plugin.__advanced?.useLegacyZuiTransformer
    })
  } : void 0,
  events: plugin.events ? await utils.records.mapValuesAsync(plugin.events, async (event) => ({
    ...event,
    schema: await utils.schema.mapZodToJsonSchema(event, {
      useLegacyZuiTransformer: plugin.__advanced?.useLegacyZuiTransformer
    })
  })) : void 0,
  actions: plugin.actions ? await utils.records.mapValuesAsync(plugin.actions, async (action) => ({
    ...action,
    input: {
      ...action.input,
      schema: await utils.schema.mapZodToJsonSchema(action.input, {
        useLegacyZuiTransformer: plugin.__advanced?.useLegacyZuiTransformer
      })
    },
    output: {
      ...action.output,
      schema: await utils.schema.mapZodToJsonSchema(action.output, {
        useLegacyZuiTransformer: plugin.__advanced?.useLegacyZuiTransformer
      })
    }
  })) : void 0,
  states: plugin.states ? utils.records.filterValues(
    await utils.records.mapValuesAsync(plugin.states, async (state) => ({
      ...state,
      schema: await utils.schema.mapZodToJsonSchema(state, {
        useLegacyZuiTransformer: plugin.__advanced?.useLegacyZuiTransformer
      })
    })),
    ({ type }) => type !== "workflow"
  ) : void 0,
  attributes: plugin.attributes
});
const prepareUpdatePluginBody = (localPlugin, remotePlugin) => {
  const actions = utils.attributes.prepareAttributeUpdateBody({
    localItems: utils.records.setNullOnMissingValues(localPlugin.actions, remotePlugin.actions),
    remoteItems: remotePlugin.actions
  });
  const events = utils.attributes.prepareAttributeUpdateBody({
    localItems: utils.records.setNullOnMissingValues(localPlugin.events, remotePlugin.events),
    remoteItems: remotePlugin.events
  });
  const states = utils.records.setNullOnMissingValues(localPlugin.states, remotePlugin.states);
  const attributes = utils.records.setNullOnMissingValues(localPlugin.attributes, remotePlugin.attributes);
  const dependencies = {
    integrations: utils.records.setNullOnMissingValues(
      localPlugin.dependencies?.integrations,
      remotePlugin.dependencies?.integrations
    ),
    interfaces: utils.records.setNullOnMissingValues(
      localPlugin.dependencies?.interfaces,
      remotePlugin.dependencies?.interfaces
    )
  };
  return {
    ...localPlugin,
    actions,
    events,
    states,
    user: localPlugin.user,
    // TODO: allow deleting user tags with null
    attributes,
    dependencies
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  prepareCreatePluginBody,
  prepareUpdatePluginBody
});
//# sourceMappingURL=plugin-body.js.map
