import { Result, ValueObject } from '@modules/shared';

interface EmailProps {
  value: string;
}

export class Email extends ValueObject<EmailProps> {
  private static readonly EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

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

  static create(email: string): Result<Email, string> {
    const normalized = email.trim().toLowerCase();
    if (!this.EMAIL_REGEX.test(normalized)) {
      return Result.err('Email không hợp lệ');
    }
    return Result.ok(new Email({ value: normalized }));
  }
}
