export const REFRESH_TOKEN_REPOSITORY = Symbol('REFRESH_TOKEN_REPOSITORY');

export interface RefreshTokenData {
  id: bigint;
  userId: bigint;
  token: string;
  deviceInfo?: string;
  ipAddress?: string;
  expiresAt: Date;
  createdAt: Date;
  revokedAt?: Date;
}

/**
 * 刷新令牌仓储接口
 */
export interface RefreshTokenRepository {
  /**
   * 根据 token 查找
   */
  findByToken(token: string): Promise<RefreshTokenData | null>;

  /**
   * 创建刷新令牌
   */
  create(data: {
    userId: bigint;
    token: string;
    deviceInfo?: string;
    ipAddress?: string;
    expiresAt: Date;
  }): Promise<RefreshTokenData>;

  /**
   * 撤销令牌
   */
  revoke(token: string): Promise<void>;

  /**
   * 撤销用户的所有令牌
   */
  revokeAllByUserId(userId: bigint): Promise<void>;

  /**
   * 删除过期令牌
   */
  deleteExpired(): Promise<number>;

  /**
   * 获取用户的活跃令牌数量
   */
  countActiveByUserId(userId: bigint): Promise<number>;
}
