import { openai } from '../agent.js';
import type { InterpreterOutput, MediaType } from '../types/agents.js';

export async function generateTitle(interpreter: InterpreterOutput, mediaType: MediaType = 'tv_show'): Promise<string> {
  const mediaLabel = mediaType === 'movie' ? 'movie' : 'TV show';

  const response = await openai.responses.create({
    model: 'gpt-5.4-mini',
    temperature: 0.7,
    service_tier: 'flex',
    instructions: `Generate a concise 5-8 word title for a ${mediaLabel} recommendation session.
Capture the essence of the user's taste — genre, tone, key themes.
Respond with ONLY the title. No quotes, no trailing punctuation.
Examples: "Dark Crime Dramas With Moral Ambiguity", "Cozy British Mysteries With Quirky Detectives"`,
    input: `Liked: ${JSON.stringify(interpreter.liked)}
Themes: ${JSON.stringify(interpreter.themes)}
Tone: ${JSON.stringify(interpreter.tone)}
Character preferences: ${JSON.stringify(interpreter.character_preferences)}`,
  });

  return (response.output_text ?? '').trim() || 'My Recommendation Session';
}
