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

describe('BreedingService', () => {
  const svc = new BreedingService();

  it('deduces baby from two parents (order A)', () => {
    expect(svc.deduceBaby('Rousse', 'Dorée')).toBe('Dorée et Rousse');
  });

  it('deduces baby from two parents (order B — bidirectional)', () => {
    expect(svc.deduceBaby('Dorée', 'Rousse')).toBe('Dorée et Rousse');
  });

  it('returns null for incompatible parents', () => {
    expect(svc.deduceBaby('Rousse', 'Rousse')).toBeNull();
  });

  it('returns null for unknown parents', () => {
    expect(svc.deduceBaby('Unknown', 'Dorée')).toBeNull();
  });

  it('lists compatible partners for Rousse', () => {
    const partners = svc.getCompatiblePartners('Rousse');
    expect(partners.length).toBeGreaterThan(0);
    expect(partners.some(p => p.partner === 'Dorée')).toBe(true);
    expect(partners.some(p => p.partner === 'Amande')).toBe(true);
  });

  it('returns empty array for unknown race', () => {
    expect(svc.getCompatiblePartners('Unknown')).toEqual([]);
  });

  it('gets parents for a baby race', () => {
    const parents = svc.getParents('Dorée et Rousse');
    expect(parents).toEqual(['Rousse', 'Dorée']);
  });

  it('returns null parents for base race', () => {
    expect(svc.getParents('Rousse')).toBeNull();
  });

  it('gets generation of a race', () => {
    expect(svc.getGeneration('Rousse')).toBe(1);
    expect(svc.getGeneration('Dorée et Rousse')).toBe(2);
  });

  it('all recipes are bidirectionally deducible', () => {
    // For every known recipe, both orderings should work
    const parents = svc.getParents('Amande et Dorée');
    expect(parents).not.toBeNull();
    if (parents) {
      expect(svc.deduceBaby(parents[0], parents[1])).toBe('Amande et Dorée');
      expect(svc.deduceBaby(parents[1], parents[0])).toBe('Amande et Dorée');
    }
  });
});
