import { RacingDomainValidationError } from '../../errors/RacingDomainError';

export type PenaltyTypeValue =
  | 'time_penalty'
  | 'grid_penalty'
  | 'points_deduction'
  | 'disqualification'
  | 'warning'
  | 'license_points'
  | 'probation'
  | 'fine'
  | 'race_ban';

export class PenaltyType {
  private constructor(private readonly value: PenaltyTypeValue) {}

  static create(value: string): PenaltyType {
    const validTypes: PenaltyTypeValue[] = [
      'time_penalty',
      'grid_penalty',
      'points_deduction',
      'disqualification',
      'warning',
      'license_points',
      'probation',
      'fine',
      'race_ban',
    ];

    if (!validTypes.includes(value as PenaltyTypeValue)) {
      throw new RacingDomainValidationError(`Invalid penalty type: ${value}`);
    }

    return new PenaltyType(value as PenaltyTypeValue);
  }

  toString(): PenaltyTypeValue {
    return this.value;
  }

  equals(other: PenaltyType): boolean {
    return this.value === other.value;
  }
}