import {
  getConeTemperature,
  getConeData,
  suggestConeFromTemperature,
  isValidCone,
  formatCone,
  getBisqueCones,
  getGlazeFiringCones,
} from '../../../src/lib/utils/coneConverter';

describe('Cone Converter', () => {
  describe('getConeTemperature', () => {
    it('returns temperature for cone 04 (bisque)', () => {
      const temp = getConeTemperature('04');
      expect(temp).not.toBeNull();
      expect(temp?.value).toBe(1945);
      expect(temp?.unit).toBe('F');
    });

    it('returns temperature for cone 6 (glaze firing)', () => {
      const temp = getConeTemperature('6');
      expect(temp).not.toBeNull();
      expect(temp?.value).toBe(2232);
      expect(temp?.unit).toBe('F');
    });

    it('returns temperature for cone 10', () => {
      const temp = getConeTemperature('10');
      expect(temp).not.toBeNull();
      expect(temp?.value).toBe(2345);
    });

    it('handles cone 06 correctly', () => {
      const temp = getConeTemperature('06');
      expect(temp).not.toBeNull();
      expect(temp?.value).toBe(1828);
    });

    it('returns null for invalid cone', () => {
      const temp = getConeTemperature('999');
      expect(temp).toBeNull();
    });
  });

  describe('getConeData', () => {
    it('returns full cone data', () => {
      const data = getConeData('6');
      expect(data).not.toBeNull();
      expect(data?.cone).toBe('6');
      expect(data?.fahrenheit).toBe(2232);
      expect(data?.celsius).toBe(1222);
      expect(data?.description).toContain('Stoneware');
    });
  });

  describe('suggestConeFromTemperature', () => {
    it('suggests cone 6 for 2232°F', () => {
      const temp = { value: 2232, unit: 'F' as const };
      const suggested = suggestConeFromTemperature(temp);
      expect(suggested).not.toBeNull();
      expect(suggested?.cone).toBe('6');
    });

    it('suggests cone 04 for 1945°F', () => {
      const temp = { value: 1945, unit: 'F' as const };
      const suggested = suggestConeFromTemperature(temp);
      expect(suggested).not.toBeNull();
      expect(suggested?.cone).toBe('04');
    });

    it('returns null for temperatures far from any cone', () => {
      const temp = { value: 500, unit: 'F' as const };
      const suggested = suggestConeFromTemperature(temp);
      expect(suggested).toBeNull();
    });
  });

  describe('isValidCone', () => {
    it('validates common cones', () => {
      expect(isValidCone('04')).toBe(true);
      expect(isValidCone('06')).toBe(true);
      expect(isValidCone('6')).toBe(true);
      expect(isValidCone('10')).toBe(true);
    });

    it('rejects invalid cones', () => {
      expect(isValidCone('99')).toBe(false);
      expect(isValidCone('abc')).toBe(false);
    });
  });

  describe('formatCone', () => {
    it('formats cone number', () => {
      expect(formatCone('04')).toBe('Cone 04');
      expect(formatCone('6')).toBe('Cone 6');
    });
  });

  describe('getBisqueCones', () => {
    it('returns common bisque cones', () => {
      const cones = getBisqueCones();
      expect(cones).toContain('04');
      expect(cones).toContain('03');
      expect(cones.length).toBeGreaterThan(0);
    });
  });

  describe('getGlazeFiringCones', () => {
    it('returns common glaze firing cones', () => {
      const cones = getGlazeFiringCones();
      expect(cones).toContain('6');
      expect(cones).toContain('10');
      expect(cones.length).toBeGreaterThan(0);
    });
  });
});
