import { describe, it, expect } from 'vitest';
import { createEnclos, addDragodinde, removeDragodinde, MAX_DD, MAX_ENCLOS, MAX_GAUGES } from '@domain/entities/Enclos';
import { createDragodinde } from '@domain/entities/Dragodinde';
import { createAccouplement } from '@domain/entities/Accouplement';

describe('Enclos', () => {
  it('creates with defaults', () => {
    const enc = createEnclos(1);
    expect(enc.id).toBe(1);
    expect(enc.name).toBe('Enclos 1');
    expect(enc.dragodindes).toHaveLength(0);
    expect(enc.activeGauges).toHaveLength(0);
    expect(enc.timer.running).toBe(false);
    expect(enc.gaugeLevels.baffeur).toBe(0);
  });

  it('adds a dragodinde', () => {
    let enc = createEnclos(1);
    enc = addDragodinde(enc);
    expect(enc.dragodindes).toHaveLength(1);
    expect(enc.dragodindes[0]!.name).toBe('Dragodinde 1');
    expect(enc.nextDdId).toBe(2);
  });

  it('increments DD id', () => {
    let enc = createEnclos(1);
    enc = addDragodinde(enc);
    enc = addDragodinde(enc);
    expect(enc.dragodindes[1]!.id).toBe(2);
    expect(enc.dragodindes[1]!.name).toBe('Dragodinde 2');
  });

  it('limits to MAX_DD', () => {
    let enc = createEnclos(1);
    for (let i = 0; i < MAX_DD + 2; i++) enc = addDragodinde(enc);
    expect(enc.dragodindes).toHaveLength(MAX_DD);
  });

  it('removes a dragodinde', () => {
    let enc = createEnclos(1);
    enc = addDragodinde(enc);
    const ddId = enc.dragodindes[0]!.id;
    enc = removeDragodinde(enc, ddId);
    expect(enc.dragodindes).toHaveLength(0);
  });

  it('remove non-existent DD is no-op', () => {
    let enc = createEnclos(1);
    enc = addDragodinde(enc);
    enc = removeDragodinde(enc, 999);
    expect(enc.dragodindes).toHaveLength(1);
  });

  it('constants are correct', () => {
    expect(MAX_DD).toBe(10);
    expect(MAX_ENCLOS).toBe(6);
    expect(MAX_GAUGES).toBe(2);
  });
});

describe('Dragodinde', () => {
  it('creates with defaults', () => {
    const dd = createDragodinde(1);
    expect(dd.id).toBe(1);
    expect(dd.name).toBe('Dragodinde 1');
    expect(dd.gender).toBe('n');
    expect(dd.stats.serenite).toBe(0);
    expect(dd.stats.xp).toBe(1);
    expect(dd.targets.baffeur).toBe(-5000);
    expect(dd.sereniteTarget).toBeNull();
    expect(dd.levelTarget).toBeNull();
  });
});

describe('Accouplement', () => {
  it('creates with all fields', () => {
    const a = createAccouplement('Rousse', 'Dorée', 'Dorée et Rousse', 2, 5, 3);
    expect(a.parentA).toBe('Rousse');
    expect(a.parentB).toBe('Dorée');
    expect(a.baby).toBe('Dorée et Rousse');
    expect(a.gen).toBe(2);
    expect(a.couples).toBe(5);
    expect(a.babiesObtained).toBe(3);
    expect(a.date).toBeTruthy();
  });
});
