Files
gridpilot.gg/core/racing/domain/value-objects/driver/DriverId.ts
2025-12-17 01:23:09 +01:00

29 lines
753 B
TypeScript

import { RacingDomainValidationError } from '../../errors/RacingDomainError';
import type { IValueObject } from '@core/shared/domain';
export interface DriverIdProps {
value: string;
}
export class DriverId implements IValueObject<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: IValueObject<DriverIdProps>): boolean {
return this.props.value === other.props.value;
}
get props(): DriverIdProps {
return { value: this.value };
}
}