import { AiMusicPromptEnhancerService } from './ai-music-prompt-enhancer.service';

describe('AiMusicPromptEnhancerService', () => {
  const service = new AiMusicPromptEnhancerService();

  it('creates a strict solo oud prompt for Arabic oud-only requests', () => {
    const result = service.enhance({
      prompt: 'بدي عزف عود فقط',
      durationSeconds: 12,
    });

    expect(result.detectedMusicIntent).toMatchObject({
      language: 'ar',
      instrument: 'oud',
      solo: true,
      percussion: 'none',
      vocals: false,
    });
    expect(result.enhancedPrompt).toContain('Solo oud performance only');
    expect(result.enhancedPrompt).toContain('No percussion, no drums');
    expect(result.enhancedPrompt).toContain('No backing instruments');
    expect(result.enhancedPrompt).toContain('Instrumental only, no vocals, no lyrics');
  });

  it('detects Arabic oud sad Hijaz maqam prompts', () => {
    const result = service.enhance({
      prompt: 'بدي عود حزين مقام حجاز',
      durationSeconds: 12,
    });

    expect(result.detectedMusicIntent).toMatchObject({
      language: 'ar',
      instrument: 'oud',
      maqam: 'hijaz',
      mood: 'sad',
      style: 'traditional_arabic',
    });
    expect(result.enhancedPrompt).toContain('oud');
    expect(result.enhancedPrompt).toContain('sad, emotional, expressive');
    expect(result.enhancedPrompt).toContain('Hijaz maqam');
    expect(result.enhancedPrompt).toContain('traditional Middle Eastern Arabic style');
  });

  it('detects Levantine calm ney prompts with light arrangement', () => {
    const result = service.enhance({
      prompt: 'موسيقى شامية هادئة مع ناي خفيف',
      durationSeconds: 12,
    });

    expect(result.detectedMusicIntent).toMatchObject({
      language: 'ar',
      instrument: 'ney',
      mood: 'calm',
      style: 'levantine',
      percussion: 'light',
    });
    expect(result.enhancedPrompt).toContain('Levantine Arabic style');
    expect(result.enhancedPrompt).toContain('calm, soft, slow');
    expect(result.enhancedPrompt).toContain('ney flute');
    expect(result.enhancedPrompt).toContain('Light subtle percussion');
  });

  it('enforces no percussion when Arabic prompt asks for no rhythm', () => {
    const result = service.enhance({
      prompt: 'بدون إيقاع',
      durationSeconds: 12,
    });

    expect(result.detectedMusicIntent.percussion).toBe('none');
    expect(result.enhancedPrompt).toContain('No percussion, no drums');
  });

  it('creates a strict solo oud prompt for English oud-only requests', () => {
    const result = service.enhance({
      prompt: 'solo oud only',
      durationSeconds: 12,
    });

    expect(result.detectedMusicIntent).toMatchObject({
      language: 'en',
      instrument: 'oud',
      solo: true,
      percussion: 'none',
    });
    expect(result.enhancedPrompt).toContain('Solo oud performance only');
    expect(result.enhancedPrompt).toContain('No backing instruments');
  });

  it('keeps existing English prompts usable', () => {
    const result = service.enhance({
      prompt: 'Calm cinematic music for a sunset scene',
      durationSeconds: 12,
    });

    expect(result.detectedMusicIntent.language).toBe('en');
    expect(result.enhancedPrompt).toContain('Instrumental Arabic Middle Eastern music piece');
    expect(result.enhancedPrompt).toContain('User idea: Calm cinematic music for a sunset scene');
  });

  it('uses optional structured fields for stronger control', () => {
    const result = service.enhance({
      prompt: 'warm intro',
      instrument: 'qanun',
      maqam: 'nahawand',
      mood: 'romantic',
      style: 'cinematic_arabic',
      tempo: 'medium',
      percussion: 'light',
      vocals: false,
    });

    expect(result.enhancedPrompt).toContain('Nahawand maqam, dramatic minor Arabic mood');
    expect(result.enhancedPrompt).toContain('romantic, warm');
    expect(result.enhancedPrompt).toContain('Instrumental Arabic qanun melody');
    expect(result.enhancedPrompt).toContain('Light subtle percussion');
    expect(result.enhancedPrompt).toContain('cinematic Arabic soundtrack');
  });
});
