import type { ValueObject } from '@core/shared/domain/ValueObject'; import { v4 as uuidv4 } from 'uuid'; import { IdentityDomainValidationError } from '../errors/IdentityDomainError'; export interface RatingEventIdProps { value: string; } export class RatingEventId implements ValueObject { readonly value: string; private constructor(value: string) { this.value = value; } static create(value: string): RatingEventId { if (!value || value.trim().length === 0) { throw new IdentityDomainValidationError('RatingEventId cannot be empty'); } const trimmed = value.trim(); // Basic UUID v4 validation const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; if (!uuidRegex.test(trimmed)) { throw new IdentityDomainValidationError( `Invalid UUID format: ${value}` ); } return new RatingEventId(trimmed); } static generate(): RatingEventId { return new RatingEventId(uuidv4()); } get props(): RatingEventIdProps { return { value: this.value }; } equals(other: ValueObject): boolean { return this.value === other.props.value; } toString(): string { return this.value; } }