"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 interface_body_exports = {};
__export(interface_body_exports, {
  prepareCreateInterfaceBody: () => prepareCreateInterfaceBody,
  prepareUpdateInterfaceBody: () => prepareUpdateInterfaceBody
});
module.exports = __toCommonJS(interface_body_exports);
var utils = __toESM(require("../utils"));
const prepareCreateInterfaceBody = async (intrface) => ({
  name: intrface.name,
  version: intrface.version,
  title: "title" in intrface ? intrface.title : void 0,
  description: "description" in intrface ? intrface.description : void 0,
  entities: intrface.entities ? await utils.records.mapValuesAsync(intrface.entities, async (entity) => ({
    ...entity,
    schema: await utils.schema.mapZodToJsonSchema(entity, {
      useLegacyZuiTransformer: intrface.__advanced?.useLegacyZuiTransformer
    })
  })) : {},
  events: intrface.events ? await utils.records.mapValuesAsync(intrface.events, async (event) => ({
    ...event,
    schema: await utils.schema.mapZodToJsonSchema(event, {
      useLegacyZuiTransformer: intrface.__advanced?.useLegacyZuiTransformer
    })
  })) : {},
  actions: intrface.actions ? await utils.records.mapValuesAsync(intrface.actions, async (action) => ({
    ...action,
    input: {
      ...action.input,
      schema: await utils.schema.mapZodToJsonSchema(action.input, {
        useLegacyZuiTransformer: intrface.__advanced?.useLegacyZuiTransformer
      })
    },
    output: {
      ...action.output,
      schema: await utils.schema.mapZodToJsonSchema(action.output, {
        useLegacyZuiTransformer: intrface.__advanced?.useLegacyZuiTransformer
      })
    }
  })) : {},
  channels: intrface.channels ? await utils.records.mapValuesAsync(intrface.channels, async (channel) => ({
    ...channel,
    messages: await utils.records.mapValuesAsync(channel.messages, async (message) => ({
      ...message,
      schema: await utils.schema.mapZodToJsonSchema(message, {
        useLegacyZuiTransformer: intrface.__advanced?.useLegacyZuiTransformer
      })
    }))
  })) : {},
  attributes: intrface.attributes
});
const prepareUpdateInterfaceBody = (localInterface, remoteInterface) => {
  const actions = utils.attributes.prepareAttributeUpdateBody({
    localItems: utils.records.setNullOnMissingValues(localInterface.actions, remoteInterface.actions),
    remoteItems: remoteInterface.actions
  });
  const events = utils.attributes.prepareAttributeUpdateBody({
    localItems: utils.records.setNullOnMissingValues(localInterface.events, remoteInterface.events),
    remoteItems: remoteInterface.events
  });
  const entities = utils.records.setNullOnMissingValues(localInterface.entities, remoteInterface.entities);
  const currentChannels = localInterface.channels ? utils.records.mapValues(localInterface.channels, (channel, channelName) => ({
    ...channel,
    messages: utils.records.setNullOnMissingValues(
      channel?.messages,
      remoteInterface.channels[channelName]?.messages
    )
  })) : void 0;
  const channels = utils.records.setNullOnMissingValues(currentChannels, remoteInterface.channels);
  const attributes = utils.records.setNullOnMissingValues(localInterface.attributes, remoteInterface.attributes);
  return {
    ...localInterface,
    entities,
    actions,
    events,
    channels,
    attributes
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  prepareCreateInterfaceBody,
  prepareUpdateInterfaceBody
});
//# sourceMappingURL=interface-body.js.map
