"""
Prompt B: Curiosity Mining (Clustered Data)

This prompt receives the SAME clustered data as the baseline, but is redesigned to:
1. Mine for specific "wait, what?" moments in the raw posts
2. Look for counterintuitive facts, surprising numbers, unexpected connections
3. Avoid abstracting into generic themes - preserve the specific hooks
4. Evaluate based on "would I click this?" not "is this a valid topic area?"
"""

PROMPT_B = """You are a viral content researcher. Your job is to find the ONE specific, surprising detail in this data that would make someone stop scrolling.

I don't want a theme analysis. I don't want "people are confused about X." I want you to identify the SINGLE MOST CLICKABLE HOOK hiding in this cluster of Reddit posts.

## THE DATA

{titles_text}

## RAW REDDIT POSTS (READ THESE CAREFULLY - THE GOLD IS HERE)

{reddit_text}

## WHAT MAKES A GREAT HOOK

The difference between mediocre and viral:

MEDIOCRE: "How to invest your money wisely"
VIRAL: "I put $50k in a 'managed fund' in 2021. It's now $55k. The S&P would have made me $75k."

MEDIOCRE: "The psychology of memory"
VIRAL: "58% of people remember the Monopoly Man having a monocle. He never had one."

MEDIOCRE: "Why people stay in bad relationships"
VIRAL: "Why therapists call it 'the hostage stage' — and why leaving triggers it"

The viral hooks share these traits:
1. SPECIFIC: A number, a name, a concrete detail
2. COUNTERINTUITIVE: Challenges what you thought you knew
3. EMOTIONALLY CHARGED: Makes you feel something (outrage, curiosity, recognition)
4. INCOMPLETE: Creates an open loop that needs closing

## YOUR TASK

Scan EVERY Reddit post in this cluster. Look for:
- Surprising numbers or statistics mentioned
- Counterintuitive outcomes people are sharing
- Specific stories that reveal a larger pattern
- "Wait, that doesn't make sense" moments
- Unexpected confessions or realizations

Then identify the SINGLE BEST HOOK.

## RESPOND IN JSON:

{{
  "hook_discovery": {{
    "source_post": "The Reddit post title that contains the hook",
    "the_raw_detail": "The specific surprising detail from that post (quote if possible)",
    "why_this_hooks": "In 1-2 sentences, why would someone stop scrolling for this?",
    "the_open_loop": "What question does this create that viewers NEED answered?"
  }},

  "video_angle": {{
    "title": "A specific, clickable title (not generic, uses the hook)",
    "first_five_seconds": "The exact words you'd say to open the video",
    "the_revelation": "What surprising truth will viewers learn?",
    "emotional_payoff": "How will viewers FEEL after watching? (must be: validated, empowered, smarter, relieved, or amused)"
  }},

  "hookability_score": {{
    "specificity": "1-5: Does the hook contain a specific detail (number, name, concrete fact)?",
    "counterintuitiveness": "1-5: How much does this challenge common assumptions?",
    "emotional_charge": "1-5: Does this make you feel something?",
    "open_loop_strength": "1-5: How badly do you need this question answered?",
    "overall": "Average of above, 1 decimal place"
  }},

  "verdict": "MAKE_NOW / WORTH_MAKING / NEEDS_RESEARCH / SKIP",
  "verdict_reasoning": "One sentence: why this verdict?"
}}

CRITICAL: If the data is full of generic questions with no specific surprising details, say so. Don't invent hooks that aren't there. Verdict should be SKIP if there's no genuine hook in the data.

Respond in JSON only. No markdown code blocks."""


def format_prompt_b(cluster_data: dict) -> str:
    """Format Prompt B with cluster data."""
    # Build titles text
    titles = [t.get('topic_name', t.get('title', '')) for t in cluster_data.get('topics', [])]
    titles_text = "\n".join([f"- {t}" for t in titles[:30]])  # Limit to 30 for context length

    # Build reddit text with FULL selftext (this is where the gold is)
    reddit_lines = []
    for i, post in enumerate(cluster_data.get('raw_posts', [])[:20]):  # Top 20 posts
        title = post.get('title', '')
        selftext = post.get('selftext', '')
        subreddit = post.get('subreddit', '')
        num_comments = post.get('num_comments', 0)

        reddit_lines.append(f"\n### Post {i+1}: r/{subreddit} ({num_comments} comments)")
        reddit_lines.append(f"**Title:** {title}")
        if selftext:
            # Include more selftext than baseline - this is where hooks hide
            reddit_lines.append(f"**Content:** {selftext[:800]}")
        reddit_lines.append("")

    reddit_text = "\n".join(reddit_lines) if reddit_lines else "No Reddit posts in this cluster."

    return PROMPT_B.format(
        titles_text=titles_text,
        reddit_text=reddit_text
    )


if __name__ == "__main__":
    # Test with sample data
    import json
    with open('test_clusters.json') as f:
        data = json.load(f)

    cluster = data['clusters'][0]
    prompt = format_prompt_b(cluster)
    print(prompt[:2000])
    print("...")
    print(f"\nTotal prompt length: {len(prompt)} chars")
