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

export type Primitive = string | boolean | number | null | undefined;

export interface IValueObjectOptions {
  label?: string;
  path?: string;
}

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

  constructor(value: T) {
    this.props = typeof value === "object" ? Object.freeze(value) : value;
  }

  get value(): T {
    return this.props;
  }

  public abstract toPrimitive(): Primitive;

  public equals(vo: ValueObject<T>): boolean {
    if (vo === null || vo === undefined) {
      return false;
    }

    if (vo.props === undefined) {
      return false;
    }

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

/*export type TComposedValueObject = {
    [key: string]: ValueObject<any>;
};
*/
