refactor
This commit is contained in:
25
core/racing/domain/entities/penalty/PenaltyStatus.ts
Normal file
25
core/racing/domain/entities/penalty/PenaltyStatus.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
|
||||
|
||||
export type PenaltyStatusValue = 'pending' | 'applied' | 'appealed' | 'overturned';
|
||||
|
||||
export class PenaltyStatus {
|
||||
private constructor(private readonly value: PenaltyStatusValue) {}
|
||||
|
||||
static create(value: string): PenaltyStatus {
|
||||
const validStatuses: PenaltyStatusValue[] = ['pending', 'applied', 'appealed', 'overturned'];
|
||||
|
||||
if (!validStatuses.includes(value as PenaltyStatusValue)) {
|
||||
throw new RacingDomainValidationError(`Invalid penalty status: ${value}`);
|
||||
}
|
||||
|
||||
return new PenaltyStatus(value as PenaltyStatusValue);
|
||||
}
|
||||
|
||||
toString(): PenaltyStatusValue {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
equals(other: PenaltyStatus): boolean {
|
||||
return this.value === other.value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user