"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const uuid = require("uuid");
const index$2 = require("./user-v6mfWQ2d.cjs");
const getInstalledAppPath = require("./getInstalledAppPath-3c7mqtrk.cjs");
const CalEventParser = require("./CalEventParser-60bHdlQO.cjs");
const SylapsApiAdapter = () => {
  return {
    getAvailability: () => {
      return Promise.resolve([]);
    },
    createMeeting: async () => {
      const meetingID = uuid.v4();
      return Promise.resolve({
        type: "sylaps_video",
        id: meetingID,
        password: "",
        url: `https://sylaps.com/r/${meetingID}`
      });
    },
    deleteMeeting: async () => {
      Promise.resolve();
    },
    updateMeeting: (bookingRef) => {
      return Promise.resolve({
        type: "sylaps_video",
        id: bookingRef.meetingId,
        password: bookingRef.meetingPassword,
        url: bookingRef.meetingUrl
      });
    }
  };
};
const SylapsApiAdapter$1 = SylapsApiAdapter;
const index$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  VideoApiAdapter: SylapsApiAdapter$1
}, Symbol.toStringTag, { value: "Module" }));
async function handler(req, res) {
  if (!req.session?.user?.id) {
    return res.status(401).json({ message: "You must be logged in to do this" });
  }
  const returnTo = req.query?.returnTo;
  const appType = CalEventParser.config.type;
  try {
    const alreadyInstalled = await index$2.prisma.credential.findFirst({
      where: {
        type: appType,
        userId: req.session.user.id
      }
    });
    if (alreadyInstalled) {
      throw new Error("Already installed");
    }
    const installation = await index$2.prisma.credential.create({
      data: {
        type: appType,
        key: {},
        userId: req.session.user.id,
        appId: CalEventParser.config.slug
      }
    });
    if (!installation) {
      throw new Error("Unable to create user credential for sylaps");
    }
  } catch (error) {
    if (error instanceof Error) {
      return res.status(500).json({ message: error.message });
    }
    return res.status(500);
  }
  return res.status(200).json({ url: returnTo ?? getInstalledAppPath.getInstalledAppPath({ variant: "conferencing", slug: CalEventParser.config.slug }) });
}
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  add: handler
}, Symbol.toStringTag, { value: "Module" }));
exports.api = index;
exports.lib = index$1;
