/**
 * SessionId Value Object
 *
 * Unique identifier for MPC sessions.
 */

import { v4 as uuidv4 } from 'uuid';

export class SessionId {
  private readonly _value: string;

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

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

  static create(value: string): SessionId {
    if (!value || value.trim().length === 0) {
      throw new Error('SessionId cannot be empty');
    }
    // UUID format validation
    const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
    if (!uuidRegex.test(value)) {
      throw new Error('Invalid SessionId format. Expected UUID format.');
    }
    return new SessionId(value);
  }

  static generate(): SessionId {
    return new SessionId(uuidv4());
  }

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

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