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

25 lines
668 B
TypeScript

import type { IValueObject } from '@core/shared/domain';
import { RacingDomainValidationError } from '../errors/RacingDomainError';
export class Points implements IValueObject<{ value: number }> {
private constructor(private readonly value: number) {}
get props(): { value: number } {
return { value: this.value };
}
static create(value: number): Points {
if (value < 0) {
throw new RacingDomainValidationError('Points cannot be negative');
}
return new Points(value);
}
toNumber(): number {
return this.value;
}
equals(other: IValueObject<{ value: number }>): boolean {
return this.value === other.props.value;
}
}