"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 channels_module_exports = {};
__export(channels_module_exports, {
  ChannelsModule: () => ChannelsModule
});
module.exports = __toCommonJS(channels_module_exports);
var import_consts = require("../../consts");
var import_generators = require("../../generators");
var gen = __toESM(require("../../generators"));
var import_module = require("../../module");
var strings = __toESM(require("../../strings"));
class MessageModule extends import_module.Module {
  constructor(name, _message) {
    super({
      path: `${name}.ts`,
      exportName: strings.varName(name)
    });
    this._message = _message;
  }
  async getContent() {
    return (0, import_generators.jsonSchemaToTypescriptZuiSchema)(
      this._message.schema,
      this.exportName,
      gen.primitiveRecordToTypescriptValues({
        title: this._message.title,
        description: this._message.description
      })
    );
  }
}
class MessagesModule extends import_module.ReExportVariableModule {
  constructor(channel) {
    super({ exportName: strings.varName("messages") });
    for (const [messageName, message] of Object.entries(channel.messages ?? {})) {
      const module2 = new MessageModule(messageName, message);
      this.pushDep(module2);
    }
  }
}
class ChannelModule extends import_module.Module {
  constructor(channelName, _channel) {
    super({
      path: import_consts.INDEX_FILE,
      exportName: strings.varName(channelName)
    });
    this._channel = _channel;
    this._messagesModule = new MessagesModule(_channel);
    this._messagesModule.unshift("messages");
    this.pushDep(this._messagesModule);
  }
  _messagesModule;
  async getContent() {
    const messageImport = this._messagesModule.import(this);
    const conversation = {
      tags: this._channel.conversation?.tags ?? {},
      creation: this._channel.conversation?.creation ?? { enabled: false, requiredTags: [] }
    };
    const message = {
      tags: this._channel.message?.tags ?? {}
    };
    return [
      import_consts.GENERATED_HEADER,
      `import { ${this._messagesModule.exportName} } from './${messageImport}'`,
      `export * from './${messageImport}'`,
      "",
      `export const ${this.exportName} = {`,
      `  title: ${gen.primitiveToTypescriptValue(this._channel.title)},`,
      `  description: ${gen.primitiveToTypescriptValue(this._channel.description)},`,
      `  messages: ${this._messagesModule.exportName},`,
      `  message: ${(0, import_generators.stringifySingleLine)(message)},`,
      `  conversation: ${(0, import_generators.stringifySingleLine)(conversation)},`,
      "}"
    ].join("\n");
  }
}
class ChannelsModule extends import_module.ReExportVariableModule {
  constructor(channels) {
    super({ exportName: strings.varName("channels") });
    for (const [channelName, channel] of Object.entries(channels)) {
      const module2 = new ChannelModule(channelName, channel);
      module2.unshift(channelName);
      this.pushDep(module2);
    }
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ChannelsModule
});
//# sourceMappingURL=channels-module.js.map
