import { ReferralRelationship } from '../aggregates';

/**
 * 推荐关系仓储接口
 */
export interface IReferralRelationshipRepository {
  /**
   * 保存推荐关系
   */
  save(relationship: ReferralRelationship): Promise<ReferralRelationship>;

  /**
   * 根据用户ID查找
   */
  findByUserId(userId: bigint): Promise<ReferralRelationship | null>;

  /**
   * 根据账户序列号查找 (用于跨服务关联)
   * @param accountSequence 格式: D + YYMMDD + 5位序号
   */
  findByAccountSequence(accountSequence: string): Promise<ReferralRelationship | null>;

  /**
   * 根据推荐码查找
   */
  findByReferralCode(code: string): Promise<ReferralRelationship | null>;

  /**
   * 查找用户的直推列表
   */
  findDirectReferrals(userId: bigint): Promise<ReferralRelationship[]>;

  /**
   * 检查推荐码是否存在
   */
  existsByReferralCode(code: string): Promise<boolean>;

  /**
   * 检查用户是否已有推荐关系
   */
  existsByUserId(userId: bigint): Promise<boolean>;

  /**
   * 获取推荐链 (用于创建新用户时)
   */
  getReferralChain(userId: bigint): Promise<bigint[]>;
}

export const REFERRAL_RELATIONSHIP_REPOSITORY = Symbol('IReferralRelationshipRepository');
