"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 bot_body_exports = {};
__export(bot_body_exports, {
  prepareCreateBotBody: () => prepareCreateBotBody,
  prepareUpdateBotBody: () => prepareUpdateBotBody
});
module.exports = __toCommonJS(bot_body_exports);
var utils = __toESM(require("../utils"));
const prepareCreateBotBody = async (bot) => ({
  user: bot.user,
  conversation: bot.conversation,
  message: bot.message,
  recurringEvents: bot.recurringEvents,
  actions: bot.actions ? await utils.records.mapValuesAsync(bot.actions, async (action) => ({
    ...action,
    input: {
      ...action.input,
      schema: await utils.schema.mapZodToJsonSchema(action.input, {
        useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer
      })
    },
    output: {
      ...action.output,
      schema: await utils.schema.mapZodToJsonSchema(action.output, {
        useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer
      })
    }
  })) : void 0,
  configuration: bot.configuration ? {
    ...bot.configuration,
    schema: await utils.schema.mapZodToJsonSchema(bot.configuration, {
      useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer
    })
  } : void 0,
  events: bot.events ? await utils.records.mapValuesAsync(bot.events, async (event) => ({
    ...event,
    schema: await utils.schema.mapZodToJsonSchema(event, {
      useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer
    })
  })) : void 0,
  states: bot.states ? utils.records.filterValues(
    await utils.records.mapValuesAsync(bot.states, async (state) => ({
      ...state,
      schema: await utils.schema.mapZodToJsonSchema(state, {
        useLegacyZuiTransformer: bot.__advanced?.useLegacyZuiTransformer
      })
    })),
    ({ type }) => type !== "workflow"
  ) : void 0,
  tags: bot.attributes
});
const prepareUpdateBotBody = (localBot, remoteBot) => ({
  ...localBot,
  states: utils.records.setNullOnMissingValues(localBot.states, remoteBot.states),
  recurringEvents: utils.records.setNullOnMissingValues(localBot.recurringEvents, remoteBot.recurringEvents),
  events: utils.attributes.prepareAttributeUpdateBody({
    localItems: utils.records.setNullOnMissingValues(localBot.events, remoteBot.events),
    remoteItems: remoteBot.events
  }),
  actions: utils.attributes.prepareAttributeUpdateBody({
    localItems: utils.records.setNullOnMissingValues(localBot.actions, remoteBot.actions),
    remoteItems: remoteBot.actions
  }),
  user: {
    ...localBot.user,
    tags: utils.records.setNullOnMissingValues(localBot.user?.tags, remoteBot.user?.tags)
  },
  conversation: {
    ...localBot.conversation,
    tags: utils.records.setNullOnMissingValues(localBot.conversation?.tags, remoteBot.conversation?.tags)
  },
  message: {
    ...localBot.message,
    tags: utils.records.setNullOnMissingValues(localBot.message?.tags, remoteBot.message?.tags)
  },
  integrations: utils.records.setNullOnMissingValues(localBot.integrations, remoteBot.integrations),
  plugins: utils.records.setNullOnMissingValues(localBot.plugins, remoteBot.plugins),
  tags: localBot.tags
  // TODO: allow removing bot tags (aka attributes) by setting to null
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  prepareCreateBotBody,
  prepareUpdateBotBody
});
//# sourceMappingURL=bot-body.js.map
