import { shallowEqual } from "shallow-equal-object";

export abstract class ValueObject<T> {
  protected readonly props: T;

  protected constructor(props: T) {
    this.props = Object.freeze(props); // 🔒 Garantiza inmutabilidad
  }

  abstract getProps(): any;

  abstract toPrimitive(): any;

  equals(other: ValueObject<T>): boolean {
    if (!(other instanceof ValueObject)) {
      return false;
    }

    if (other.props === undefined || other.props === null) {
      return false;
    }

    return shallowEqual(this.props, other.props);
  }
}
