import { describe, expect, it } from 'vitest';
import {
  generateSoundRecipe,
  generateSoundTitle,
} from '@/business/audio-files/generate';

describe('generateSoundRecipe (local stub)', () => {
  it('produces a playable single-voice recipe with 3-5 valid notes', () => {
    // Random output — exercise it many times to cover the range.
    for (let run = 0; run < 30; run += 1) {
      const recipe = generateSoundRecipe();
      expect(recipe.voices).toHaveLength(1);

      const voice = recipe.voices[0];
      expect(['sine', 'triangle']).toContain(voice.waveform);
      expect(voice.notes.length).toBeGreaterThanOrEqual(3);
      expect(voice.notes.length).toBeLessThanOrEqual(5);

      for (const note of voice.notes) {
        expect(note.freq).toBeGreaterThan(0);
        expect(note.duration).toBeGreaterThan(0);
        expect(note.startAt).toBeGreaterThanOrEqual(0);
        expect(note.gain).toBeGreaterThan(0);
        expect(note.gain).toBeLessThanOrEqual(1);
      }
    }
  });

  it('returns a non-empty title', () => {
    expect(generateSoundTitle().trim().length).toBeGreaterThan(0);
  });
});
