#!/usr/bin/env python3
"""Build the Cropster Discovery Brief Google Doc."""
import subprocess
import json

DOC_ID = "1Gi-5bRcy9co9Uq_5Q5tekdUOzPpF3bRPOdZ8-SeASVU"
ENV = {"GOOGLE_APPLICATION_CREDENTIALS": "/home/clawd/secrets/google/kitt-workspace-token.json"}

# Full document content as list of (text, style) tuples
# style: TITLE, SUBTITLE, HEADING_1, HEADING_2, HEADING_3, NORMAL_TEXT
sections = [
    ("Cropster × CE\n", "TITLE"),
    ("Discovery Brief — April 2026\n", "SUBTITLE"),
    ("\n", "NORMAL_TEXT"),
    ("How to use this\n", "HEADING_2"),
    ("This isn't a questionnaire. Don't fill it in alone.\n\nSit with your brand person and your ops manager for 45 minutes and work through this together. We'll use it to build a scoped, priced proposal and to start the engagement the right way.\n\nThe more specific you are, the less time we waste getting to useful work.\n\n", "NORMAL_TEXT"),
    ("—\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("01 — The Business Moment\n", "HEADING_1"),
    ("What are you actually trying to achieve in the next 6 months? (Not the marketing version — the business version.)\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("What is the May launch, specifically? What changes, what goes live, what's at stake if it doesn't land?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("What does success look like for your CRO and CEO by end of Q3?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("What's the investor pressure? What does Verdane need to see this year?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("02 — Your Customers\n", "HEADING_1"),
    ("List the customer types you sell to:\n", "HEADING_3"),
    ("(e.g. small roasteries, mid-size roasters, cafe chains, wholesalers, enterprise producers like Starbucks/Blue Bottle, regional distributors)\n\n\n\n", "NORMAL_TEXT"),
    ("Which segments are growing? Which are the target for the new pricing/packaging?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("Which segments have the worst messaging problem right now — where the old positioning is most broken?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("Do you have any segment-specific material? (Case studies, testimonials, win stories, customer quotes)\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("What are the top 3 things customers misunderstand about Cropster?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("03 — The 150-Slide Deck\n", "HEADING_1"),
    ("Can you share the consultant deck with us?\n", "HEADING_3"),
    ("[ ] Yes, I'll attach it\n[ ] Under NDA — I'll share a summary or the key slides\n[ ] Not yet — here's why: ___\n\n", "NORMAL_TEXT"),
    ("What's the single most important thing the deck says that your current marketing language doesn't reflect?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("What's the biggest internal debate about the new positioning?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("04 — Your Data Assets\n", "HEADING_1"),
    ("Go through this list with your ops manager. Mark what exists and who owns it.\n\n", "NORMAL_TEXT"),
    ("Sales call recordings / transcripts\n", "HEADING_3"),
    ("Have / Don't have     Volume: ___     Owner: ___\n\n", "NORMAL_TEXT"),
    ("CRM win/loss data\n", "HEADING_3"),
    ("Have / Don't have     System: ___     Owner: ___\n\n", "NORMAL_TEXT"),
    ("Website analytics (GA4 or equivalent)\n", "HEADING_3"),
    ("Have / Don't have     Accessible to us: Yes / No\n\n", "NORMAL_TEXT"),
    ("Trustpilot / G2 / Capterra reviews\n", "HEADING_3"),
    ("Have / Don't have     Platforms: ___\n\n", "NORMAL_TEXT"),
    ("Customer feedback surveys (NPS, CSAT, post-onboarding)\n", "HEADING_3"),
    ("Have / Don't have     Last run: ___\n\n", "NORMAL_TEXT"),
    ("Social listening / brand mention tracking\n", "HEADING_3"),
    ("Have / Don't have     Tool: ___\n\n", "NORMAL_TEXT"),
    ("Email performance data\n", "HEADING_3"),
    ("Have / Don't have     Platform: ___\n\n", "NORMAL_TEXT"),
    ("Support / helpdesk tickets (for signal on pain points)\n", "HEADING_3"),
    ("Have / Don't have     System: ___\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("05 — Your Stack\n", "HEADING_1"),
    ("What tools does marketing currently use? (CRM, email platform, social scheduling, analytics, design, content)\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("Who manages the website? Is there a CMS? What's the rebuild timeline?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("Where do the current brand guidelines live? How old are they?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("06 — The Team\n", "HEADING_1"),
    ("Who will be the day-to-day contact at Cropster for this engagement?\n", "HEADING_3"),
    ("Name:             Role:             Email:\n\n", "NORMAL_TEXT"),
    ("Who is the brand/TOV person you're assigning or hiring?\n", "HEADING_3"),
    ("Name:             Status: In role / Hiring now / TBD\n\n", "NORMAL_TEXT"),
    ("Who is the ops/data manager we'd work with on data access?\n", "HEADING_3"),
    ("Name:             Role:\n\n", "NORMAL_TEXT"),
    ("Who needs to approve things before they go external?\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("07 — What You Don't Want\n", "HEADING_1"),
    ("You were clear in our call. Write it here for the record.\n\nWhat are you explicitly NOT ready for right now?\n", "NORMAL_TEXT"),
    ("(e.g. full rebrand, social content production, paid campaigns, tone-of-voice overhaul, visual identity changes)\n", "HEADING_3"),
    ("\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("08 — Anything Else\n", "HEADING_1"),
    ("Is there anything we should know that we haven't asked?\n", "HEADING_3"),
    ("\n\n\n\n", "NORMAL_TEXT"),
    ("\n", "NORMAL_TEXT"),
    ("—\n\n", "NORMAL_TEXT"),
    ("Send this to lukas@curiousendeavor.com by April 14.\nWe'll respond with a scoped proposal by April 17.\n", "NORMAL_TEXT"),
]

# Build all text first
all_text = ""
for text, _ in sections:
    all_text += text

print(f"Total characters: {len(all_text)}")

# Build the batchUpdate requests
# First: insert all text at index 1
requests = []

# Insert full text at position 1 (before the existing \n)
requests.append({
    "insertText": {
        "location": {"index": 1},
        "text": all_text
    }
})

# Now calculate indices and apply styles
# We insert at index 1, so the text starts at index 1
# Each paragraph ends with \n, and the next starts right after
idx = 1
style_requests = []

for text, style in sections:
    end_idx = idx + len(text)
    
    if style != "NORMAL_TEXT":
        style_requests.append({
            "updateParagraphStyle": {
                "range": {
                    "startIndex": idx,
                    "endIndex": end_idx
                },
                "paragraphStyle": {
                    "namedStyleType": style
                },
                "fields": "namedStyleType"
            }
        })
    
    idx = end_idx

print(f"Style requests: {len(style_requests)}")

# Combine: first insert text, then apply styles
all_requests = requests + style_requests

payload = {"requests": all_requests}

# Write to temp file
with open("/tmp/cropster-brief-payload.json", "w") as f:
    json.dump(payload, f)

print("Payload written to /tmp/cropster-brief-payload.json")
print(f"Total requests: {len(all_requests)}")
