import { Phone } from '../value-objects';

export const SMS_VERIFICATION_REPOSITORY = Symbol('SMS_VERIFICATION_REPOSITORY');

export enum SmsVerificationType {
  REGISTER = 'REGISTER',
  LOGIN = 'LOGIN',
  RESET_PASSWORD = 'RESET_PASSWORD',
  CHANGE_PHONE = 'CHANGE_PHONE',
}

export interface SmsVerificationData {
  id: bigint;
  phone: Phone;
  code: string;
  type: SmsVerificationType;
  expiresAt: Date;
  verifiedAt?: Date;
  attempts: number;
  createdAt: Date;
}

/**
 * 短信验证码仓储接口
 */
export interface SmsVerificationRepository {
  /**
   * 创建验证码
   */
  create(data: {
    phone: Phone;
    code: string;
    type: SmsVerificationType;
    expiresAt: Date;
  }): Promise<SmsVerificationData>;

  /**
   * 查找最新的有效验证码
   */
  findLatestValid(phone: Phone, type: SmsVerificationType): Promise<SmsVerificationData | null>;

  /**
   * 增加尝试次数
   */
  incrementAttempts(id: bigint): Promise<void>;

  /**
   * 标记为已验证
   */
  markAsVerified(id: bigint): Promise<void>;

  /**
   * 获取今日发送次数
   */
  getDailySendCount(phone: Phone): Promise<number>;

  /**
   * 删除过期验证码
   */
  deleteExpired(): Promise<number>;
}
