import { NotificationChannel } from '../entities/notification.entity';

/**
 * Value Object for Notification Channel.
 * Encapsulates channel validation and provides type-safe channel handling.
 */
export class NotificationChannelVO {
  private static readonly VALID_CHANNELS = new Set<string>(
    Object.values(NotificationChannel),
  );

  private constructor(private readonly _value: NotificationChannel) {}

  static create(channel: string): NotificationChannelVO {
    if (!NotificationChannelVO.VALID_CHANNELS.has(channel)) {
      throw new Error(
        `Invalid notification channel: "${channel}". Valid channels: ${Array.from(NotificationChannelVO.VALID_CHANNELS).join(', ')}`,
      );
    }
    return new NotificationChannelVO(channel as NotificationChannel);
  }

  static fromEnum(channel: NotificationChannel): NotificationChannelVO {
    return new NotificationChannelVO(channel);
  }

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

  /**
   * Whether this channel requires an external delivery provider (not just DB storage).
   */
  get requiresExternalDelivery(): boolean {
    return this._value !== NotificationChannel.IN_APP;
  }

  /**
   * Whether this channel supports rich content (HTML, markdown).
   */
  get supportsRichContent(): boolean {
    return this._value === NotificationChannel.EMAIL;
  }

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

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