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

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

  static create(value: string): SponsorEmail {
    if (!value || value.trim().length === 0) {
      throw new RacingDomainValidationError('Sponsor contact email cannot be empty');
    }
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailRegex.test(value)) {
      throw new RacingDomainValidationError('Invalid sponsor contact email format');
    }
    return new SponsorEmail(value.trim());
  }

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

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