25 lines
657 B
TypeScript
25 lines
657 B
TypeScript
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
import type { IValueObject } from '@core/shared/domain';
|
|
|
|
export class DriverId implements IValueObject<string> {
|
|
private constructor(private readonly value: string) {}
|
|
|
|
static create(value: string): DriverId {
|
|
if (!value || value.trim().length === 0) {
|
|
throw new RacingDomainValidationError('Driver ID cannot be empty');
|
|
}
|
|
return new DriverId(value.trim());
|
|
}
|
|
|
|
toString(): string {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: IValueObject<string>): boolean {
|
|
return this.value === other.props;
|
|
}
|
|
|
|
get props(): string {
|
|
return this.value;
|
|
}
|
|
} |