export interface RegistrationCodeMessage {
  challengeId: string;
  code: string;
  email: string;
  purpose: "register" | "login" | "admin_login" | "account_delete";
}

export interface ResendAdapter {
  sendVerificationCode(message: RegistrationCodeMessage): Promise<void>;
}

export class MockResendAdapter implements ResendAdapter {
  readonly calls: RegistrationCodeMessage[] = [];

  async sendVerificationCode(message: RegistrationCodeMessage) {
    this.calls.push({ ...message });
  }

  readLatestCode(email: string) {
    const normalizedEmail = email.trim().toLowerCase();
    const call = this.calls.findLast((candidate) => candidate.email === normalizedEmail);
    if (!call) throw new Error("No mock registration message exists for that email.");
    return call.code;
  }
}
