/**
 * ShareId Value Object
 *
 * Unique identifier for party shares.
 */

export class ShareId {
  private readonly _value: string;

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

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

  static create(value: string): ShareId {
    if (!value || value.trim().length === 0) {
      throw new Error('ShareId cannot be empty');
    }
    // Format: share_{timestamp}_{random}
    const shareIdRegex = /^share_\d+_[a-z0-9]+$/;
    if (!shareIdRegex.test(value)) {
      throw new Error('Invalid ShareId format');
    }
    return new ShareId(value);
  }

  static generate(): ShareId {
    const timestamp = Date.now();
    const random = Math.random().toString(36).substring(2, 11);
    return new ShareId(`share_${timestamp}_${random}`);
  }

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

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