import { RacingDomainValidationError } from '../../errors/RacingDomainError';

export class Url {
  private constructor(private readonly value: string) {}

  static create(value: string): Url {
    if (!value || value.trim().length === 0) {
      throw new RacingDomainValidationError('URL cannot be empty');
    }
    try {
      new URL(value);
    } catch {
      throw new RacingDomainValidationError('Invalid URL format');
    }
    return new Url(value.trim());
  }

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

  equals(other: Url): boolean {
    return this.value === other.value;
  }
}