import { DomainEvent } from './domain-event.base';

/**
 * 推荐关系创建事件
 */
export class ReferralRelationshipCreatedEvent extends DomainEvent {
  constructor(
    public readonly userId: bigint,
    public readonly referrerId: bigint | null,
    public readonly referralCode: string,
    public readonly referralChain: bigint[],
  ) {
    super();
  }

  get eventName(): string {
    return 'referral.relationship.created';
  }

  toPayload(): Record<string, unknown> {
    return {
      eventId: this.eventId,
      eventName: this.eventName,
      occurredAt: this.occurredAt.toISOString(),
      data: {
        userId: this.userId.toString(),
        referrerId: this.referrerId?.toString() ?? null,
        referralCode: this.referralCode,
        referralChain: this.referralChain.map((id) => id.toString()),
      },
    };
  }
}
