import { verifyOtp } from "./otpStore.service";

// OTP Verification Handler Function
export const verifyOtpHandler = async (
  email: string,
  otp: string
): Promise<{ status: number; message: string }> => {
  try {
    // Verify OTP after successful login attempt
    const isOtpValid = verifyOtp(email, otp);
    if (!isOtpValid) {
      return { status: 401, message: "Invalid or expired OTP" };
    }

    return { status: 200, message: "OTP verified successfully" };
  } catch (err: any) {
    console.error(err);
    return { status: 500, message: err.message };
  }
};
