Files
2026-01-16 19:46:49 +01:00

29 lines
762 B
TypeScript

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