24 lines
700 B
TypeScript
24 lines
700 B
TypeScript
import { RacingDomainValidationError } from '../errors/RacingDomainError';
|
|
|
|
export class CountryCode {
|
|
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: CountryCode): boolean {
|
|
return this.value === other.value;
|
|
}
|
|
} |