export class Email {
  private constructor(private readonly address: string) {}

  static create(address: string): Email {
    if (!address || address.trim().length === 0) {
      throw new Error('Email address cannot be empty');
    }
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailRegex.test(address)) {
      throw new Error('Invalid email address format');
    }
    if (address.length > 100) {
      throw new Error('Email address must not exceed 100 characters');
    }
    return new Email(address.toLowerCase().trim());
  }

  static fromString(address: string): Email {
    return new Email(address);
  }

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

  equals(other: Email): boolean {
    return this.address === other.address;
  }

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