import { H as HttpError } from "./http-error-RJXCPZV2.js";
import { C as CredentialRepository } from "./credential-INULiwKH.js";
import { p as prisma } from "./orgDomains-eTg-cjth.js";
async function checkInstalled(slug, userId) {
  const alreadyInstalled = await CredentialRepository.findByAppIdAndUserId({ appId: slug, userId });
  if (alreadyInstalled) {
    throw new HttpError({ statusCode: 422, message: "Already installed" });
  }
}
async function createDefaultInstallation({
  appType,
  user,
  slug,
  key = {},
  teamId,
  billingCycleStart,
  paymentStatus,
  subscriptionId
}) {
  const installation = await prisma.credential.create({
    data: {
      type: appType,
      key,
      ...teamId ? { teamId } : { userId: user.id },
      appId: slug,
      subscriptionId,
      paymentStatus,
      billingCycleStart
    }
  });
  if (!installation) {
    throw new Error(`Unable to create user credential for type ${appType}`);
  }
  return installation;
}
export {
  createDefaultInstallation as a,
  checkInstalled as c
};
