#!/usr/bin/env python3
"""Add Phat Foods Ch1 v2 content to Notion page."""

import os
import requests

API_KEY = open(os.path.expanduser("~/.config/notion/api_key")).read().strip()
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
    "Notion-Version": "2022-06-28"
}

PAGE_ID = "2f8330c2-8646-81f5-87ce-caa7e4a94479"

blocks = [
    {"type": "heading_1", "heading_1": {"rich_text": [{"type": "text", "text": {"content": "Chapter 1: Why Plant-Based Failed"}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Context Setting — The Gap PHAT Fills"}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 2
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 2: The Promise That Didn't Pay Off"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: Plant-based dairy hit a wall."}}], "icon": {"emoji": "📌"}}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "The category peaked. Now it's retreating."}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Milk alternatives: 15% market share. The win."}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Cheese and butter: 1.6%. The failure."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "~2/3 of plant-based consumers have returned to conventional dairy. 83% of plant-based milk buyers switched back."}}]}},
    {"type": "quote", "quote": {"rich_text": [{"type": "text", "text": {"content": "This isn't a growth story. It's a product problem."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Sources: GFI/PBFA Market Research 2024; SPINS Webinar Dec 2025"}, "annotations": {"italic": True}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 3
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 3: The Great Retreat"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: The halo faded. The habit didn't stick."}}], "icon": {"emoji": "📌"}}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Over 1/4 of all U.S. consumers are lapsed plant-based purchasers."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "The market: $8.1B in 2024, down from its peak. Plant-based foods now represent just 1.1% of total retail food."}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Plant-based milks declined 3.3%"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Cow dairy volumes increased 6.1%"}}]}},
    {"type": "quote", "quote": {"rich_text": [{"type": "text", "text": {"content": "The closer you try to replicate dairy, the harder you fail."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Sources: Mintel 2023; AHDB/Dairy Foods 2025"}, "annotations": {"italic": True}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 4
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 4: The Consumer Verdict"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: They tried it. They didn't come back."}}], "icon": {"emoji": "📌"}}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "73% of consumers want improved plant-based cheese that actually mimics dairy."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "The failure modes are consistent:"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Flavor: Off-tastes, aftertaste, \"plastic\""}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Texture: Grainy, rubbery, won't melt"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Performance: Oily when heated, gummy when cooled"}}]}},
    {"type": "quote", "quote": {"rich_text": [{"type": "text", "text": {"content": "Vegans accept compromises. Flexitarians don't. And flexitarians are the market."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Sources: NIH Prospective Review 2023; Consumer Perception Study 2025"}, "annotations": {"italic": True}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 5
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 5: The Category Split"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: Milk made it. Cheese didn't. Here's why."}}], "icon": {"emoji": "📌"}}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Milk alternatives don't need to melt, stretch, or create mouth-coating richness."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Cheese and butter do."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "And that requires dairy fat chemistry—the precise symphony of 400+ fatty acids that plant oils can't replicate."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Premium pricing worked when plant-based was a \"health halo\" product. \"Ultra-processed\" concerns tarnished that image. \"Almost as good\" at double the price doesn't sell."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Sources: GFI 2024; International Food Information Council Survey"}, "annotations": {"italic": True}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 6
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 6: Plant-Based Missed the Molecular Target"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: The science was always incomplete."}}], "icon": {"emoji": "📌"}}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Real dairy fat contains 400+ fatty acids in precise ratios."}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "The magic molecules? Short-Chain Fatty Acids (SCFAs)."}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Butyric acid (C4): The \"butter\" in butter"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Caproic/Caprylic acids (C6-C8): Creamy mouthfeel"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Capric acid (C10): Clean dairy flavor release"}}]}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Plant oils—coconut, palm, soy—have zero SCFAs. Wrong chain lengths entirely."}}]}},
    {"type": "quote", "quote": {"rich_text": [{"type": "text", "text": {"content": "For 15 years, the industry worked around a molecular gap. Nobody closed it."}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 7
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 7: Why Now"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: Three forces converging."}}], "icon": {"emoji": "📌"}}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "Precision fermentation matured. The technology to grow specific molecules is finally scalable."}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "Big dairy is listening. Danone, Nestlé, Arla—all actively seeking ingredient partners."}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "\"Plant-based\" lost its shine. The category needs a breakthrough, not another oat product."}}]}},
    {"type": "quote", "quote": {"rich_text": [{"type": "text", "text": {"content": "PHAT arrives at the exact moment the industry needs a new answer."}}]}},
    {"type": "divider", "divider": {}},
    
    # Slide 8
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Slide 8: The Opportunity"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Headline: Nobody has cracked SCFAs. Until now."}}], "icon": {"emoji": "📌"}}},
    {"type": "paragraph", "paragraph": {"rich_text": [{"type": "text", "text": {"content": "Competitive Comparison:"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Savor (Thermochemical) — Cannot produce SCFAs ✗"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Melt & Marble (Yeast fermentation) — Cannot produce SCFAs ✗"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Nourish (Fungal fermentation) — Cannot produce SCFAs ✗"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "Yali Bio (Synthetic biology) — Cannot produce SCFAs ✗"}}]}},
    {"type": "bulleted_list_item", "bulleted_list_item": {"rich_text": [{"type": "text", "text": {"content": "PHAT (Microalgae) — CAN produce SCFAs ✓"}}]}},
    {"type": "quote", "quote": {"rich_text": [{"type": "text", "text": {"content": "The others can make fat. PHAT can make dairy fat. That's the difference."}}]}},
    {"type": "divider", "divider": {}},
    
    # Summary
    {"type": "heading_2", "heading_2": {"rich_text": [{"type": "text", "text": {"content": "Chapter Summary"}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "Plant-based peaked and retreated (market failure)"}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "Consumers tried it, didn't repeat (product failure)"}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "The molecular gap explains why (scientific diagnosis)"}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "Three forces create the opening (timing)"}}]}},
    {"type": "numbered_list_item", "numbered_list_item": {"rich_text": [{"type": "text", "text": {"content": "PHAT is the only solution (competitive positioning)"}}]}},
    {"type": "callout", "callout": {"rich_text": [{"type": "text", "text": {"content": "Viewer takeaway: The market needs what PHAT has. Nobody else can deliver it."}}], "icon": {"emoji": "🎯"}}},
]

# Add blocks in batches
for i in range(0, len(blocks), 100):
    batch = blocks[i:i+100]
    resp = requests.patch(
        f"https://api.notion.com/v1/blocks/{PAGE_ID}/children",
        headers=HEADERS,
        json={"children": batch}
    )
    if resp.status_code != 200:
        print(f"Error: {resp.status_code} - {resp.text[:200]}")
    else:
        print(f"Added {len(batch)} blocks")

print("Done!")
