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

export class EventName {
  static readonly APP_SESSION_START = new EventName('app_session_start');
  static readonly PRESENCE_HEARTBEAT = new EventName('presence_heartbeat');
  static readonly APP_SESSION_END = new EventName('app_session_end');

  private readonly _value: string;

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

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

  static fromString(value: string): EventName {
    if (!value || value.trim() === '') {
      throw new DomainException('EventName cannot be empty');
    }
    const trimmed = value.trim().toLowerCase();
    if (trimmed.length > 64) {
      throw new DomainException('EventName cannot exceed 64 characters');
    }
    if (!/^[a-z][a-z0-9_]*$/.test(trimmed)) {
      throw new DomainException('EventName must start with a letter and contain only lowercase letters, numbers, and underscores');
    }
    return new EventName(trimmed);
  }

  isDauEvent(): boolean {
    return this._value === EventName.APP_SESSION_START.value;
  }

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

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