25 lines
638 B
TypeScript
25 lines
638 B
TypeScript
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
import type { IValueObject } from '@core/shared/domain';
|
|
|
|
export class TrackLength implements IValueObject<number> {
|
|
private constructor(private readonly value: number) {}
|
|
|
|
get props(): number {
|
|
return this.value;
|
|
}
|
|
|
|
static create(value: number): TrackLength {
|
|
if (value <= 0) {
|
|
throw new RacingDomainValidationError('Track length must be positive');
|
|
}
|
|
return new TrackLength(value);
|
|
}
|
|
|
|
toNumber(): number {
|
|
return this.value;
|
|
}
|
|
|
|
equals(other: IValueObject<number>): boolean {
|
|
return this.value === other.props;
|
|
}
|
|
} |