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

describe('TeamRatingDelta', () => {
  describe('create', () => {
    it('should create valid delta values', () => {
      expect(TeamRatingDelta.create(0).value).toBe(0);
      expect(TeamRatingDelta.create(10).value).toBe(10);
      expect(TeamRatingDelta.create(-10).value).toBe(-10);
      expect(TeamRatingDelta.create(100).value).toBe(100);
      expect(TeamRatingDelta.create(-100).value).toBe(-100);
      expect(TeamRatingDelta.create(50.5).value).toBe(50.5);
      expect(TeamRatingDelta.create(-50.5).value).toBe(-50.5);
    });

    it('should throw for values outside range', () => {
      expect(() => TeamRatingDelta.create(100.1)).toThrow(RacingDomainValidationError);
      expect(() => TeamRatingDelta.create(-100.1)).toThrow(RacingDomainValidationError);
      expect(() => TeamRatingDelta.create(101)).toThrow(RacingDomainValidationError);
      expect(() => TeamRatingDelta.create(-101)).toThrow(RacingDomainValidationError);
    });

    it('should accept zero', () => {
      const delta = TeamRatingDelta.create(0);
      expect(delta.value).toBe(0);
    });

    it('should throw for non-numeric values', () => {
      expect(() => TeamRatingDelta.create('50' as unknown as number)).toThrow();
      expect(() => TeamRatingDelta.create(null as unknown as number)).toThrow();
      expect(() => TeamRatingDelta.create(undefined as unknown as number)).toThrow();
    });

    it('should return true for same value', () => {
      const delta1 = TeamRatingDelta.create(10);
      const delta2 = TeamRatingDelta.create(10);
      expect(delta1.equals(delta2)).toBe(true);
    });

    it('should return false for different values', () => {
      const delta1 = TeamRatingDelta.create(10);
      const delta2 = TeamRatingDelta.create(-10);
      expect(delta1.equals(delta2)).toBe(false);
    });

    it('should handle decimal comparisons', () => {
      const delta1 = TeamRatingDelta.create(50.5);
      const delta2 = TeamRatingDelta.create(50.5);
      expect(delta1.equals(delta2)).toBe(true);
    });

    it('should expose props correctly', () => {
      const delta = TeamRatingDelta.create(10);
      expect(delta.props.value).toBe(10);
    });

    it('should return numeric value', () => {
      const delta = TeamRatingDelta.create(50.5);
      expect(delta.toNumber()).toBe(50.5);
    });

    it('should return string representation', () => {
      const delta = TeamRatingDelta.create(50.5);
      expect(delta.toString()).toBe('50.5');
    });

    it('should return true for positive deltas', () => {
      expect(TeamRatingDelta.create(1).isPositive()).toBe(true);
      expect(TeamRatingDelta.create(100).isPositive()).toBe(true);
    });

    it('should return false for zero and negative deltas', () => {
      expect(TeamRatingDelta.create(0).isPositive()).toBe(false);
      expect(TeamRatingDelta.create(-1).isPositive()).toBe(false);
    });

    it('should return true for negative deltas', () => {
      expect(TeamRatingDelta.create(-1).isNegative()).toBe(true);
      expect(TeamRatingDelta.create(-100).isNegative()).toBe(true);
    });

    it('should return false for zero and positive deltas', () => {
      expect(TeamRatingDelta.create(0).isNegative()).toBe(false);
      expect(TeamRatingDelta.create(1).isNegative()).toBe(false);
    });

    it('should return true for zero delta', () => {
      expect(TeamRatingDelta.create(0).isZero()).toBe(true);
    });

    it('should return false for non-zero deltas', () => {
      expect(TeamRatingDelta.create(1).isZero()).toBe(false);
      expect(TeamRatingDelta.create(-1).isZero()).toBe(false);
    });
  });
});