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