import { DomainEntity } from "./domain-entity";
import { IDomainEvent } from "./events";

export abstract class AggregateRoot<T extends object> extends DomainEntity<T> {
  private _domainEvents: IDomainEvent[] = [];

  private logDomainEventAdded(event: IDomainEvent): void {
    const thisClass = Reflect.getPrototypeOf(this);
    const domainEventClass = Reflect.getPrototypeOf(event);
  }

  /**
   * Agregar un evento de dominio al agregado
   */
  protected addDomainEvent(event: IDomainEvent): void {
    this._domainEvents.push(event);

    // Log the domain event
    this.logDomainEventAdded(event);
  }

  /**
   * Obtener los eventos de dominio pendientes
   */
  get domainEvents(): IDomainEvent[] {
    return this._domainEvents;
  }

  /**
   * Limpiar la lista de eventos después de procesarlos
   */
  public clearDomainEvents(): void {
    this._domainEvents.splice(0, this._domainEvents.length);
  }
}
