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

/**
 * 更新日志值对象
 */
export class Changelog {
  private readonly _value: string;

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

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

  static create(value: string): Changelog {
    // 允许空值，返回默认 changelog
    if (!value || value.trim() === '') {
      return Changelog.empty();
    }

    const trimmed = value.trim();

    if (trimmed.length > 5000) {
      throw new DomainException('Changelog cannot exceed 5000 characters');
    }

    return new Changelog(trimmed);
  }

  static empty(): Changelog {
    return new Changelog('No changelog provided');
  }

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

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