49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import type { ValueObject } from '@core/shared/domain/ValueObject';
|
|
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
export interface TeamRatingDimensionKeyProps {
|
|
value: 'driving' | 'adminTrust';
|
|
}
|
|
|
|
const VALID_DIMENSIONS = ['driving', 'adminTrust'] as const;
|
|
|
|
export class TeamRatingDimensionKey implements ValueObject<TeamRatingDimensionKeyProps> {
|
|
readonly value: TeamRatingDimensionKeyProps['value'];
|
|
|
|
private constructor(value: TeamRatingDimensionKeyProps['value']) {
|
|
this.value = value;
|
|
}
|
|
|
|
static create(value: string): TeamRatingDimensionKey {
|
|
if (!value || value.trim().length === 0) {
|
|
throw new RacingDomainValidationError('Team rating dimension key cannot be empty');
|
|
}
|
|
|
|
// Strict validation: no leading/trailing whitespace allowed
|
|
if (value !== value.trim()) {
|
|
throw new RacingDomainValidationError(
|
|
`Team rating dimension key cannot have leading or trailing whitespace: "${value}"`
|
|
);
|
|
}
|
|
|
|
if (!VALID_DIMENSIONS.includes(value as TeamRatingDimensionKeyProps['value'])) {
|
|
throw new RacingDomainValidationError(
|
|
`Invalid team rating dimension key: ${value}. Valid options: ${VALID_DIMENSIONS.join(', ')}`
|
|
);
|
|
}
|
|
|
|
return new TeamRatingDimensionKey(value as TeamRatingDimensionKeyProps['value']);
|
|
}
|
|
|
|
get props(): TeamRatingDimensionKeyProps {
|
|
return { value: this.value };
|
|
}
|
|
|
|
equals(other: ValueObject<TeamRatingDimensionKeyProps>): boolean {
|
|
return this.value === other.props.value;
|
|
}
|
|
|
|
toString(): string {
|
|
return this.value;
|
|
}
|
|
} |