export class Phone {
  private constructor(private readonly number: string) {}

  static create(number: string): Phone {
    if (!number || number.trim().length === 0) {
      throw new Error('Phone number cannot be empty');
    }
    // Strip whitespace and dashes for validation
    const cleaned = number.replace(/[\s\-()]/g, '');
    // Must start with optional + and contain 7-15 digits
    const phoneRegex = /^\+?\d{7,15}$/;
    if (!phoneRegex.test(cleaned)) {
      throw new Error('Invalid phone number format');
    }
    return new Phone(cleaned);
  }

  static fromString(number: string): Phone {
    return new Phone(number);
  }

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

  equals(other: Phone): boolean {
    return this.number === other.number;
  }

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