import crypto from "crypto";

export function generateInvitationToken() {
  const token = crypto.randomBytes(32).toString("hex");
  const tokenHash = crypto.createHash("sha256").update(token).digest("hex");
  return { token, tokenHash };
}

export function hashInvitationToken(token: string) {
  return crypto.createHash("sha256").update(token).digest("hex");
}

export function getInviteTtlHours() {
  const parsed = Number(process.env.INVITE_TTL_HOURS ?? 72);
  return Number.isFinite(parsed) && parsed > 0 ? parsed : 72;
}

export function getInviteExpiresAt() {
  const ttlHours = getInviteTtlHours();
  return new Date(Date.now() + ttlHours * 60 * 60 * 1000);
}
