import { c, b, j, g, a, h, A, d, e, i, f, O } from "./email-manager-K3-nXYto.js";
import { t as totpRawCheck } from "./verifyEmail-Pv_FK1vq.js";
import { a as a2, s } from "./verifyEmail-Pv_FK1vq.js";
import { createHash } from "crypto";
import { p as prisma } from "./i18n-49-r55rr.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 {
  c as AttendeeCancelledEmail,
  b as AttendeeDeclinedEmail,
  j as AttendeeRequestEmail,
  g as AttendeeRescheduledEmail,
  a as AttendeeScheduledEmail,
  h as AttendeeUpdatedEmail,
  A as AttendeeVerifyEmail,
  d as OrganizerCancelledEmail,
  e as OrganizerReassignedEmail,
  i as OrganizerRequestEmail,
  f as OrganizerRescheduledEmail,
  O as OrganizerScheduledEmail,
  a2 as sendEmailVerificationByCode,
  s as sendSignupToOrganizationEmail,
  verifyEmailCodeHandler
};
