Files
gridpilot.gg/core/racing/domain/value-objects/RaceName.ts
2026-01-16 16:46:57 +01:00

38 lines
957 B
TypeScript

import type { ValueObject } from '@core/shared/domain/ValueObject';
export interface RaceNameProps {
value: string;
}
export class RaceName implements ValueObject<RaceNameProps> {
public readonly props: RaceNameProps;
private constructor(value: string) {
if (!value || !value.trim()) {
throw new Error('Race name cannot be empty');
}
if (value.trim().length < 3) {
throw new Error('Race name must be at least 3 characters long');
}
if (value.trim().length > 100) {
throw new Error('Race name must not exceed 100 characters');
}
this.props = { value: value.trim() };
}
public static fromString(value: string): RaceName {
return new RaceName(value);
}
get value(): string {
return this.props.value;
}
public toString(): string {
return this.props.value;
}
public equals(other: ValueObject<RaceNameProps>): boolean {
return this.props.value === other.props.value;
}
}