/**
 * Password reset token domain. Pure types and rules.
 */
export interface PasswordResetToken {
  id: string;
  userId: string;
  tokenHash: string;
  expiresAt: Date;
  usedAt: Date | null;
  createdAt: Date;
}

export class InvalidResetTokenError extends Error {
  constructor() {
    super('Invalid or expired password reset token');
    this.name = 'InvalidResetTokenError';
  }
}

export function isTokenUsable(token: PasswordResetToken, now: Date = new Date()): boolean {
  if (token.usedAt !== null) return false;
  if (token.expiresAt.getTime() <= now.getTime()) return false;
  return true;
}

export const RESET_TOKEN_TTL_MS = 60 * 60 * 1000; // 1 hour