import { U, T, $, Y, R, Z, Q, V, W, _, X, S } from "./email-manager-RBMYQEU9.js";
import { t as totpRawCheck } from "./verifyEmail-zhbkTOtH.js";
import { a, s } from "./verifyEmail-zhbkTOtH.js";
import { createHash } from "crypto";
import { p as prisma } from "./user--mpkKOwW.js";
import { TRPCError } from "@trpc/server";
const verifyEmailCodeHandler = async ({ ctx, input }) => {
  const { code, email, teamId } = input;
  const { id } = ctx.user;
  if (!code || !email)
    throw new TRPCError({ code: "BAD_REQUEST" });
  const secret = createHash("md5").update(email + process.env.CALENDSO_ENCRYPTION_KEY).digest("hex");
  const isValidToken = totpRawCheck(code, secret, { step: 900 });
  if (!isValidToken)
    throw new TRPCError({ code: "BAD_REQUEST", message: "invalid_code" });
  await prisma.verifiedEmail.create({
    data: {
      email,
      userId: id,
      teamId
    }
  });
  return isValidToken;
};
export {
  U as AttendeeCancelledEmail,
  T as AttendeeDeclinedEmail,
  $ as AttendeeRequestEmail,
  Y as AttendeeRescheduledEmail,
  R as AttendeeScheduledEmail,
  Z as AttendeeUpdatedEmail,
  Q as AttendeeVerifyEmail,
  V as OrganizerCancelledEmail,
  W as OrganizerReassignedEmail,
  _ as OrganizerRequestEmail,
  X as OrganizerRescheduledEmail,
  S as OrganizerScheduledEmail,
  a as sendEmailVerificationByCode,
  s as sendSignupToOrganizationEmail,
  verifyEmailCodeHandler
};
