import os
from openai import OpenAI

client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

# Example JTBD (replace with file input if you like)
JTBD_TEXT = """
When I try to track calories, but I become obsessive, 
I want to manage my eating without mental strain, 
so I can lose weight without harming my mental health.
"""

def call_api(prompt):
    response = client.chat.completions.create(
        model="gpt-4o-mini",   # or gpt-4o for higher quality
        messages=[{"role": "user", "content": prompt}],
        temperature=0.7
    )
    return response.choices[0].message.content.strip()

# 1. Expanded Narrative
prompt1 = f"""
Expand the following JTBD into a detailed **Expanded Narrative**:
{JTBD_TEXT}

Write 2–3 paragraphs that elaborate on the situation, struggle, consequences, and desired outcomes.
Be descriptive, empathetic, and specific. Avoid suggesting solutions or products.
"""

# 2. Jobs + Forces of Progress
prompt2 = f"""
Expand the following JTBD into a **Jobs + Forces of Progress narrative**:
{JTBD_TEXT}

Tell the story using the four forces: Push (struggles), Pull (desired outcomes), Anxieties (barriers), Habits (current workarounds).
Write 2–3 paragraphs, clear and structured.
"""

# 3. Persona-style Story
prompt3 = f"""
Rewrite the following JTBD as a **Persona-style story**:
{JTBD_TEXT}

Use first-person voice, like: "As someone who..., I struggle with..., I wish..., but..."
Keep it empathetic and specific, 1–2 paragraphs.
"""

# 4. Insight Statement
prompt4 = f"""
Rewrite the following JTBD as a concise **Insight Statement**:
{JTBD_TEXT}

Format: "Users need a way to ___ because ___."
Make it punchy and research-style, 1–2 sentences.
"""

# Run each call separately
expanded_narrative = call_api(prompt1)
forces_narrative = call_api(prompt2)
persona_story = call_api(prompt3)
insight_statement = call_api(prompt4)

# Print results
print("\n=== Expanded Narrative ===\n", expanded_narrative)
print("\n=== Jobs + Forces of Progress ===\n", forces_narrative)
print("\n=== Persona-style Story ===\n", persona_story)
print("\n=== Insight Statement ===\n", insight_statement)
