31 lines
819 B
TypeScript
31 lines
819 B
TypeScript
import type { ValueObject } from '@core/shared/domain/ValueObject';
|
|
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
export class ImageUrl implements ValueObject<string> {
|
|
private constructor(private readonly value: string) {}
|
|
|
|
static create(value: string): ImageUrl {
|
|
if (!value || value.trim().length === 0) {
|
|
throw new RacingDomainValidationError('Image URL cannot be empty');
|
|
}
|
|
// Basic URL validation
|
|
try {
|
|
new URL(value);
|
|
} catch {
|
|
throw new RacingDomainValidationError('Invalid image URL format');
|
|
}
|
|
return new ImageUrl(value.trim());
|
|
}
|
|
|
|
toString(): string {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: ValueObject<string>): boolean {
|
|
return this.props === other.props;
|
|
}
|
|
|
|
get props(): string {
|
|
return this.value;
|
|
}
|
|
} |