import { describe, it, expect } from 'vitest';
import { InventaireCalculator } from '@domain/services/InventaireCalculator';

describe('InventaireCalculator', () => {
  const calc = new InventaireCalculator();

  it('empty inventory produces nothing', () => {
    const r = calc.compute({});
    expect(r.generations).toHaveLength(0);
  });

  it('zero stock produces nothing', () => {
    const r = calc.compute({ 'Rousse': { m: 0, f: 0 } });
    expect(r.generations).toHaveLength(0);
  });

  it('\u2642 Rousse + \u2640 Dor\u00e9e produces Dor\u00e9e et Rousse', () => {
    const r = calc.compute({
      'Rousse': { m: 1, f: 0 },
      'Dor\u00e9e': { m: 0, f: 1 },
    });
    expect(r.generations.length).toBeGreaterThanOrEqual(1);
    const gen2 = r.generations.find(g => g.gen === 2);
    expect(gen2).toBeDefined();
    expect(gen2!.crossings.some(c => c.name === 'Dor\u00e9e et Rousse')).toBe(true);
  });

  it('\u2640 Rousse + \u2642 Dor\u00e9e also produces (reversed genders)', () => {
    const r = calc.compute({
      'Rousse': { m: 0, f: 1 },
      'Dor\u00e9e': { m: 1, f: 0 },
    });
    const gen2 = r.generations.find(g => g.gen === 2);
    expect(gen2).toBeDefined();
    expect(gen2!.crossings.some(c => c.name === 'Dor\u00e9e et Rousse')).toBe(true);
  });

  it('same gender cannot breed (\u2642+\u2642)', () => {
    const r = calc.compute({
      'Rousse': { m: 2, f: 0 },
      'Dor\u00e9e': { m: 2, f: 0 },
    });
    expect(r.generations).toHaveLength(0);
  });

  it('same gender cannot breed (\u2640+\u2640)', () => {
    const r = calc.compute({
      'Rousse': { m: 0, f: 2 },
      'Dor\u00e9e': { m: 0, f: 2 },
    });
    expect(r.generations).toHaveLength(0);
  });

  it('babies cascade to next generation', () => {
    const r = calc.compute({
      'Rousse': { m: 2, f: 2 },
      'Amande': { m: 2, f: 2 },
      'Dor\u00e9e': { m: 2, f: 2 },
    });
    const gen2 = r.generations.find(g => g.gen === 2);
    expect(gen2).toBeDefined();
    expect(gen2!.crossings.length).toBeGreaterThan(0);
    // Check if gen 3 exists (cascade from gen 2 babies)
    // This depends on whether gen 2 babies can breed with each other
  });

  it('multiple pairs produce multiple babies', () => {
    const r = calc.compute({
      'Rousse': { m: 3, f: 3 },
      'Dor\u00e9e': { m: 3, f: 3 },
    });
    const gen2 = r.generations.find(g => g.gen === 2);
    expect(gen2).toBeDefined();
    const dr = gen2!.crossings.find(c => c.name === 'Dor\u00e9e et Rousse');
    expect(dr).toBeDefined();
    // With 3\u2642+3\u2640 of each, we can make up to 3 pairs (limited by one side)
    expect(dr!.qty).toBeGreaterThanOrEqual(3);
  });
});
