import { DomainException } from '../../shared/exceptions/domain.exception';

/**
 * 版本号值对象
 * Android: Integer (递增)
 * iOS: Integer (递增)
 */
export class VersionCode {
  private readonly _value: number;

  private constructor(value: number) {
    this._value = value;
  }

  get value(): number {
    return this._value;
  }

  static create(value: number): VersionCode {
    if (!Number.isInteger(value)) {
      throw new DomainException('VersionCode must be an integer');
    }
    if (value <= 0) {
      throw new DomainException('VersionCode must be positive');
    }
    if (value > 2147483647) {
      throw new DomainException('VersionCode cannot exceed 2147483647');
    }
    return new VersionCode(value);
  }

  isNewerThan(other: VersionCode): boolean {
    return this._value > other._value;
  }

  equals(other: VersionCode): boolean {
    return this._value === other._value;
  }

  toString(): string {
    return this._value.toString();
  }
}
