Files
gridpilot.gg/core/racing/domain/value-objects/CountryCode.ts
2026-01-16 19:46:49 +01:00

30 lines
860 B
TypeScript

import type { ValueObject } from '@core/shared/domain/ValueObject';
import { RacingDomainValidationError } from '../errors/RacingDomainError';
export class CountryCode implements ValueObject<string> {
private constructor(private readonly value: string) {}
static create(value: string): CountryCode {
if (!value || value.trim().length === 0) {
throw new RacingDomainValidationError('Country code is required');
}
const trimmed = value.trim().toUpperCase();
if (!/^[A-Z]{2,3}$/.test(trimmed)) {
throw new RacingDomainValidationError('Country must be a valid ISO code (2-3 letters)');
}
return new CountryCode(trimmed);
}
toString(): string {
return this.value;
}
equals(other: ValueObject<string>): boolean {
return this.value === other.props;
}
get props(): string {
return this.value;
}
}