29 lines
769 B
TypeScript
29 lines
769 B
TypeScript
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
|
|
import type { IValueObject } from '@core/shared/domain';
|
|
|
|
export interface DriverNameProps {
|
|
value: string;
|
|
}
|
|
|
|
export class DriverName implements IValueObject<DriverNameProps> {
|
|
private constructor(private readonly value: string) {}
|
|
|
|
static create(value: string): DriverName {
|
|
if (!value || value.trim().length === 0) {
|
|
throw new RacingDomainValidationError('Driver name is required');
|
|
}
|
|
return new DriverName(value.trim());
|
|
}
|
|
|
|
toString(): string {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: IValueObject<DriverNameProps>): boolean {
|
|
return this.props.value === other.props.value;
|
|
}
|
|
|
|
get props(): DriverNameProps {
|
|
return { value: this.value };
|
|
}
|
|
} |