Files
gridpilot.gg/core/racing/domain/value-objects/CarName.ts
2025-12-27 19:18:54 +01:00

36 lines
696 B
TypeScript

import { z } from "zod";
const CarNameSchema = z
.string()
.trim()
.min(1, "Car name cannot be empty")
.max(100, "Car name must be 100 characters or less");
export class CarName {
private readonly _value: string;
private constructor(value: string) {
this._value = value;
}
static create(value: string): CarName {
const validated = CarNameSchema.parse(value);
return new CarName(validated);
}
static fromString(value: string): CarName {
return new CarName(value);
}
get value(): string {
return this._value;
}
equals(other: CarName): boolean {
return this._value === other._value;
}
toString(): string {
return this._value;
}
}