"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getChannelSettings = exports.ensureChatId = exports.createChatMessage = void 0;
var _dataSources = require("@mirai/data-sources");
const createChatMessage = async function () {
  let {
    author,
    body,
    chatId,
    meta,
    session
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  if (!chatId) return null;
  try {
    return await (0, _dataSources.request)({
      endpoint: "/api/chats/".concat(chatId, "/messages"),
      hostname: process.env.SERVICE_LOBBY,
      method: 'POST',
      headers: {
        'x-mcp-secret': process.env.MCP_SECRET
      },
      author,
      body,
      meta,
      session
    });
  } catch (_unused) {
    return null;
  }
};
exports.createChatMessage = createChatMessage;
const ensureChatId = async function () {
  let {
    fingerprint,
    channelId,
    session
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  if (!fingerprint || !channelId) return null;
  try {
    var _ensured$chat;
    const ensured = await (0, _dataSources.request)({
      endpoint: '/api/chats/ensure',
      hostname: process.env.SERVICE_LOBBY,
      method: 'POST',
      headers: {
        'x-mcp-secret': process.env.MCP_SECRET
      },
      fingerprint,
      channelId,
      session
    });
    return (ensured === null || ensured === void 0 ? void 0 : (_ensured$chat = ensured.chat) === null || _ensured$chat === void 0 ? void 0 : _ensured$chat.id) || null;
  } catch (_unused2) {
    return null;
  }
};
exports.ensureChatId = ensureChatId;
const getChannelSettings = async function () {
  let {
    channelId
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  if (!channelId) return null;
  try {
    return await (0, _dataSources.request)({
      endpoint: "/api/channels/".concat(channelId, "/settings/public"),
      hostname: process.env.SERVICE_LOBBY,
      method: 'GET'
    });
  } catch (_unused3) {
    return null;
  }
};
exports.getChannelSettings = getChannelSettings;
//# sourceMappingURL=lobby.service.js.map