// NBA pace factors (Session 15) — static lookup table tests.

const pace = require('../../src/data/paceFactors');

describe('PACE_FACTORS', () => {
  test('covers all 30 NBA teams', () => {
    expect(Object.keys(pace.PACE_FACTORS).length).toBe(30);
  });

  test('every entry is a finite integer near 100', () => {
    for (const [code, val] of Object.entries(pace.PACE_FACTORS)) {
      expect(typeof val).toBe('number');
      expect(Number.isFinite(val)).toBe(true);
      expect(val).toBeGreaterThanOrEqual(90);
      expect(val).toBeLessThanOrEqual(110);
      expect(code).toMatch(/^[A-Z]{2,3}$/);
    }
  });

  test('Indiana / Sacramento / Atlanta are at the fast end', () => {
    expect(pace.PACE_FACTORS.IND).toBeGreaterThanOrEqual(103);
    expect(pace.PACE_FACTORS.SAC).toBeGreaterThanOrEqual(103);
    expect(pace.PACE_FACTORS.ATL).toBeGreaterThanOrEqual(102);
  });

  test('Orlando / New York / Cleveland are at the slow end', () => {
    expect(pace.PACE_FACTORS.ORL).toBeLessThanOrEqual(96);
    expect(pace.PACE_FACTORS.NYK).toBeLessThanOrEqual(96);
    expect(pace.PACE_FACTORS.CLE).toBeLessThanOrEqual(98);
  });
});

describe('getPaceFactor', () => {
  test('returns the value for known teams', () => {
    expect(pace.getPaceFactor('IND')).toBe(pace.PACE_FACTORS.IND);
  });
  test('case-insensitive + trimmed', () => {
    expect(pace.getPaceFactor(' ind ')).toBe(pace.PACE_FACTORS.IND);
    expect(pace.getPaceFactor('sac')).toBe(pace.PACE_FACTORS.SAC);
  });
  test('null for unknown', () => {
    expect(pace.getPaceFactor('XYZ')).toBeNull();
    expect(pace.getPaceFactor('')).toBeNull();
    expect(pace.getPaceFactor(null)).toBeNull();
  });

  describe('legacy team aliases', () => {
    test('NJN resolves to BKN', () => {
      expect(pace.getPaceFactor('NJN')).toBe(pace.PACE_FACTORS.BKN);
    });
    test('NOH resolves to NOP', () => {
      expect(pace.getPaceFactor('NOH')).toBe(pace.PACE_FACTORS.NOP);
    });
    test('SEA resolves to OKC', () => {
      expect(pace.getPaceFactor('SEA')).toBe(pace.PACE_FACTORS.OKC);
    });
    test('CHO resolves to CHA', () => {
      expect(pace.getPaceFactor('CHO')).toBe(pace.PACE_FACTORS.CHA);
    });
  });
});

describe('immutability', () => {
  test('PACE_FACTORS frozen', () => {
    expect(Object.isFrozen(pace.PACE_FACTORS)).toBe(true);
  });
  test('ALIASES frozen', () => {
    expect(Object.isFrozen(pace.ALIASES)).toBe(true);
  });
});
