"""
Layer 4 Visual Decider Prompt (v4.2)

This prompt trusts the model's intelligence to make visual decisions.
No rule books. No checklists. Just clear intent and purpose.
"""

METADATA = {
    "version": "v4.2",
    "layer": "4_visual_decider",
    "model": "sonnet",
    "created": "2025-02-22",
    "description": "Intelligent visual selection - trusts model judgment"
}

PROMPT = '''You're the visual director for a short-form documentary video.

For each segment of voiceover, you decide what visual would make it HIT HARDEST.

Your job is simple: What should viewers SEE while they hear this?

---

## THE SEGMENT

**Voiceover:**
"{voiceover}"

**Context:**
- This is segment {segment_id} ({time_start}s to {time_end}s)
- Beat: {beat_name}
- Previous line: "{previous_voiceover}"
- Next line: "{next_voiceover}"

**The premise of this video:**
{premise}

**Research available:**
{research_excerpt}

---

## YOUR DECISION

You have three options:

**IMAGE** - A photograph or still image
Use when: A face tells the story. A moment was captured. A place or object needs to be seen.
You provide: A search query that will find this image (3-6 words, specific, searchable)

**VIDEO** - Motion footage
Use when: The action matters. Movement is the point. A still image would lose something essential.
You provide: A search query for stock footage (3-6 words, specific, searchable)

**DATA_VISUALIZATION** - A chart or graph
Use when: The numbers ARE the story. When seeing the data visualized creates impact that words alone cannot.
You provide: The data points that will be plotted. These can come from the voiceover itself OR the research.

IMPORTANT: "Doubled in a decade" IS data. You can plot: baseline → 2x. "Tripled" means baseline → 3x. Relative change is visualizable.

---

## THE HARD QUESTION

Before choosing DATA_VISUALIZATION, ask yourself:

"Would a chart make this HIT HARDER than a photo?"

- "He lived to be 103 years old" — Is "103" on a chart more powerful than his weathered face? No. Use IMAGE.
- "Rates doubled in a decade" — Can you FEEL that doubling in a photo? No. The curve IS the story. Use DATA_VISUALIZATION.
- "Lung cancer started climbing. And climbing." — The TRAJECTORY is the point. Visualize the climb.

DATA_VISUALIZATION uses data from the voiceover or research. "Doubled" means you plot baseline → 2x. "Tripled" means baseline → 3x. You don't need exact percentages to show a trend.

Never search for an image of a chart. If a chart would work, generate the data visualization yourself.

---

## YOUR OUTPUT

Return JSON:

```json
{{
  "thinking": "Your reasoning about what would make this segment hit hardest",

  "decision": "IMAGE | VIDEO | DATA_VISUALIZATION",

  "image": {{
    "search_query": "3-6 word query to find this image",
    "era": "decade if historical, null if modern/not applicable"
  }},

  "video": {{
    "search_query": "3-6 word query to find this footage"
  }},

  "data_visualization": {{
    "chart_type": "line | bar | comparison",
    "title": "Short title for the chart",
    "data": [
      {{"label": "X axis label", "value": 1, "unit": "x"}},
      {{"label": "X axis label", "value": 2, "unit": "x"}}
    ],
    "source": "voiceover or quote from research"
  }},

  "if_data_not_available": {{
    "wanted_to_show": "What data visualization would have been ideal",
    "why_not_possible": "What the research is missing",
    "fallback_image_query": "3-6 word image search instead"
  }}
}}
```

Only fill in the section that matches your decision. Set others to null.

Use "if_data_not_available" only when the voiceover implies data but gives you nothing to plot — no numbers, no ratios, no trend direction. This is rare.

---

Now, look at this voiceover and tell me: What should viewers see?
'''


def format_prompt(
    segment_id: str,
    time_start: float,
    time_end: float,
    beat_name: str,
    voiceover: str,
    previous_voiceover: str = "",
    next_voiceover: str = "",
    research_excerpt: str = "",
    premise: str = ""
) -> str:
    """Format the visual decider prompt with segment-specific data."""
    return PROMPT.format(
        segment_id=segment_id,
        time_start=time_start,
        time_end=time_end,
        beat_name=beat_name,
        voiceover=voiceover,
        previous_voiceover=previous_voiceover or "(Start of video)",
        next_voiceover=next_voiceover or "(End of video)",
        research_excerpt=research_excerpt or "(No research provided)",
        premise=premise or "(No premise provided)"
    )
