import type { ValueObject } from '@core/shared/domain/ValueObject';
import { RacingDomainValidationError } from '../errors/RacingDomainError';

export class TrackImageUrl implements ValueObject<string | undefined> {
  private constructor(private readonly value: string | undefined) {}

  get props(): string | undefined {
    return this.value;
  }

  static create(value: string | undefined): TrackImageUrl {
    // Allow undefined or valid URL, but for simplicity, just check if string is not empty if provided
    if (value !== undefined && value.trim().length === 0) {
      throw new RacingDomainValidationError('Track image URL cannot be empty string');
    }
    return new TrackImageUrl(value);
  }

  toString(): string | undefined {
    return this.value;
  }

  equals(other: ValueObject<string | undefined>): boolean {
    return this.value === other.props;
  }
}