import { ContributionRecordAggregate } from '../aggregates/contribution-record.aggregate';
import { ContributionSourceType } from '../aggregates/contribution-account.aggregate';

/**
 * 贡献值记录仓库接口
 */
export interface IContributionRecordRepository {
  /**
   * 保存记录
   */
  save(record: ContributionRecordAggregate, tx?: any): Promise<ContributionRecordAggregate>;

  /**
   * 批量保存
   */
  saveMany(records: ContributionRecordAggregate[], tx?: any): Promise<ContributionRecordAggregate[]>;

  /**
   * 根据账户序列号查找
   */
  findByAccountSequence(
    accountSequence: string,
    options?: {
      page?: number;
      limit?: number;
      sourceType?: ContributionSourceType;
      includeExpired?: boolean;
    },
  ): Promise<{
    items: ContributionRecordAggregate[];
    total: number;
  }>;

  /**
   * 根据来源认种ID查找
   */
  findBySourceAdoptionId(sourceAdoptionId: bigint): Promise<ContributionRecordAggregate[]>;

  /**
   * 查找需要过期的记录
   */
  findExpiring(beforeDate: Date, limit?: number): Promise<ContributionRecordAggregate[]>;

  /**
   * 批量标记过期
   */
  markExpiredBatch(ids: bigint[], tx?: any): Promise<number>;

  /**
   * 获取账户的有效贡献值总和
   */
  getEffectiveContributionSum(accountSequence: string): Promise<string>;

  /**
   * 检查是否已经为某个认种分配过贡献值
   */
  existsBySourceAdoptionId(sourceAdoptionId: bigint): Promise<boolean>;
}

export const CONTRIBUTION_RECORD_REPOSITORY = Symbol('IContributionRecordRepository');
