import { describe, expect, it } from 'vitest';
import { RacingDomainValidationError } from '../../errors/RacingDomainError';
import { PenaltyType } from './PenaltyType';

describe('PenaltyType', () => {
  describe('create', () => {
    it('should create a PenaltyType with valid value', () => {
      const type = PenaltyType.create('time_penalty');
      expect(type.toString()).toBe('time_penalty');
    });

    it('should create all valid types', () => {
      const validTypes = [
        'time_penalty',
        'grid_penalty',
        'points_deduction',
        'disqualification',
        'warning',
        'license_points',
        'probation',
        'fine',
        'race_ban',
      ];

      validTypes.forEach(typeValue => {
        const type = PenaltyType.create(typeValue);
        expect(type.toString()).toBe(typeValue);
      });
    });

    it('should throw error for invalid type', () => {
      expect(() => PenaltyType.create('invalid_type')).toThrow(RacingDomainValidationError);
    });

    it('should throw error for empty string', () => {
      expect(() => PenaltyType.create('')).toThrow(RacingDomainValidationError);
    });
  });

  describe('equals', () => {
    it('should return true for equal types', () => {
      const type1 = PenaltyType.create('time_penalty');
      const type2 = PenaltyType.create('time_penalty');
      expect(type1.equals(type2)).toBe(true);
    });

    it('should return false for different types', () => {
      const type1 = PenaltyType.create('time_penalty');
      const type2 = PenaltyType.create('grid_penalty');
      expect(type1.equals(type2)).toBe(false);
    });
  });
});