import { v4 } from "uuid";
import { p as prisma } from "./orgDomains-eTg-cjth.js";
import { g as getInstalledAppPath } from "./getInstalledAppPath-vg9hE5pP.js";
import { M as config } from "./CalEventParser-NbcDfXYU.js";
const SylapsApiAdapter = () => {
  return {
    getAvailability: () => {
      return Promise.resolve([]);
    },
    createMeeting: async () => {
      const meetingID = 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 = config.type;
  try {
    const alreadyInstalled = await prisma.credential.findFirst({
      where: {
        type: appType,
        userId: req.session.user.id
      }
    });
    if (alreadyInstalled) {
      throw new Error("Already installed");
    }
    const installation = await prisma.credential.create({
      data: {
        type: appType,
        key: {},
        userId: req.session.user.id,
        appId: 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({ variant: "conferencing", slug: config.slug }) });
}
const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  add: handler
}, Symbol.toStringTag, { value: "Module" }));
export {
  index as api,
  index$1 as lib
};
