#!/usr/bin/env python3
"""Restyle Brandwatch deck with CE branding, visuals, and proper layout."""

from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload
import json, os, time

PRESENTATION_ID = "1MRxdQp2Njr-Z5s45c_kV3oC4X-devR4_u5_LpLQ6MpA"
ASSETS = "/root/.openclaw/workspace/public/brandwatch-v2/assets"

with open('/root/.config/gws/credentials.json') as f:
    creds_data = json.load(f)

creds = Credentials(
    token=None,
    refresh_token=creds_data['refresh_token'],
    token_uri=creds_data['token_uri'],
    client_id=creds_data['client_id'],
    client_secret=creds_data['client_secret']
)

slides_service = build('slides', 'v1', credentials=creds)
drive_service = build('drive', 'v3', credentials=creds)

def pt(val):
    return int(val * 12700)

def inch(val):
    return int(val * 914400)

# CE Colors
CE_RED = {'red': 0.8, 'green': 0, 'blue': 0}
CE_BLACK = {'red': 0.102, 'green': 0.102, 'blue': 0.102}
CE_DARK = {'red': 0.08, 'green': 0.08, 'blue': 0.08}
CE_GREY = {'red': 0.4, 'green': 0.4, 'blue': 0.4}
CE_LIGHT = {'red': 0.6, 'green': 0.6, 'blue': 0.6}
CE_WHITE = {'red': 1, 'green': 1, 'blue': 1}
CE_OFF_WHITE = {'red': 0.97, 'green': 0.97, 'blue': 0.97}

PAGE_W = 9144000
PAGE_H = 5143500

def upload_image(filepath):
    """Upload image to Drive and return URL."""
    fname = os.path.basename(filepath)
    media = MediaFileUpload(filepath, resumable=True)
    file_meta = {'name': fname}
    f = drive_service.files().create(body=file_meta, media_body=media, fields='id,webContentLink').execute()
    # Make publicly accessible
    drive_service.permissions().create(
        fileId=f['id'],
        body={'type': 'anyone', 'role': 'reader'}
    ).execute()
    url = f"https://drive.google.com/uc?id={f['id']}&export=download"
    return url, f['id']

print("Getting presentation...")
pres = slides_service.presentations().get(presentationId=PRESENTATION_ID).execute()
slides = pres['slides']

# ── PHASE 1: Delete all slides and rebuild from scratch ──
print("Deleting existing slides and rebuilding...")

# Delete all existing slides except first
delete_requests = []
for s in slides[1:]:
    delete_requests.append({'deleteObject': {'objectId': s['objectId']}})

if delete_requests:
    slides_service.presentations().batchUpdate(
        presentationId=PRESENTATION_ID,
        body={'requests': delete_requests}
    ).execute()

# Delete first slide content
pres = slides_service.presentations().get(presentationId=PRESENTATION_ID).execute()
first_slide = pres['slides'][0]
clear_requests = []
for el in first_slide.get('pageElements', []):
    clear_requests.append({'deleteObject': {'objectId': el['objectId']}})
if clear_requests:
    slides_service.presentations().batchUpdate(
        presentationId=PRESENTATION_ID,
        body={'requests': clear_requests}
    ).execute()

# ── PHASE 2: Upload images ──
print("Uploading images...")
images = {}
for name in ['assaf.png', 'lukas.png', 'kitt.png', 'gerri.png', 'ogilvy.png', 
             'tatiana.png', 'anton.png', 'julia.png', 'jessica.jpg', 'thibault.png',
             'brandwatch-logo.svg']:
    path = os.path.join(ASSETS, name)
    if os.path.exists(path) and not name.endswith('.svg'):
        url, fid = upload_image(path)
        images[name.split('.')[0]] = url
        print(f"  Uploaded {name}")
        time.sleep(0.3)

# ── PHASE 3: Build all slides ──
print("Building slides...")

SLIDE_DEFS = [
    # Slide 0: Title (dark bg)
    {
        'id': 'bw_slide_0', 'bg': CE_RED,
        'elements': [
            {'type': 'text', 'text': 'BRANDWATCH × CURIOUS ENDEAVOR', 
             'x': inch(0.8), 'y': inch(1.5), 'w': inch(8.4), 'h': inch(1),
             'font_size': 36, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Your partner that turns social intelligence into action.\nFinished creative, deployed across markets, in days instead of months.',
             'x': inch(0.8), 'y': inch(2.8), 'w': inch(7), 'h': inch(1.2),
             'font_size': 18, 'color': CE_WHITE, 'bold': False, 'font': 'Arial', 'alpha': 0.8},
            {'type': 'text', 'text': 'curiousendeavor.com/brandwatch-v2',
             'x': inch(0.8), 'y': inch(4.5), 'w': inch(5), 'h': inch(0.4),
             'font_size': 12, 'color': CE_WHITE, 'bold': False, 'font': 'Arial', 'alpha': 0.5},
        ]
    },
    # Slide 1: The Opportunity
    {
        'id': 'bw_slide_1', 'bg': CE_WHITE,
        'elements': [
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(0.8), 'y': inch(0.6), 'w': inch(0.4), 'h': pt(3), 'fill': CE_RED},
            {'type': 'text', 'text': 'THE OPPORTUNITY',
             'x': inch(1.4), 'y': inch(0.5), 'w': inch(4), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Brandwatch is the world\'s best\nsocial intelligence platform.',
             'x': inch(0.8), 'y': inch(1.3), 'w': inch(8), 'h': inch(0.9),
             'font_size': 32, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Your clients invest $100K–$500K/year for enterprise-grade social data.\n\nBut data without action is just expensive reporting.\n\nThe gap between insight and creative response costs brands months\nand hundreds of thousands in agency fees.\n\nWe close that gap.',
             'x': inch(0.8), 'y': inch(2.6), 'w': inch(7.5), 'h': inch(2.5),
             'font_size': 16, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 2: What Agencies Charge
    {
        'id': 'bw_slide_2', 'bg': CE_BLACK,
        'elements': [
            {'type': 'text', 'text': 'WHAT AGENCIES CHARGE TODAY',
             'x': inch(0.8), 'y': inch(0.5), 'w': inch(6), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': '$200K–$1M+',
             'x': inch(0.8), 'y': inch(1.0), 'w': inch(8), 'h': inch(1),
             'font_size': 54, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'per year in agency fees — on top of the Brandwatch license',
             'x': inch(0.8), 'y': inch(2.0), 'w': inch(7), 'h': inch(0.5),
             'font_size': 18, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Campaign strategy + brief                    $5K–$15K\nCreative development                            $10K–$50K\nMulti-market localization (per market)     $3K–$8K\nFull campaign (strategy → assets)           $25K–$150K\nTimeline                                                    6–12 weeks',
             'x': inch(0.8), 'y': inch(3.0), 'w': inch(7), 'h': inch(2),
             'font_size': 14, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 3: What We Do
    {
        'id': 'bw_slide_3', 'bg': CE_WHITE,
        'elements': [
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(0.8), 'y': inch(0.6), 'w': inch(0.4), 'h': pt(3), 'fill': CE_RED},
            {'type': 'text', 'text': 'WHAT WE DO',
             'x': inch(1.4), 'y': inch(0.5), 'w': inch(4), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'AI-native creative production.\nFrom Brandwatch data to campaign-ready assets.',
             'x': inch(0.8), 'y': inch(1.3), 'w': inch(8), 'h': inch(0.9),
             'font_size': 28, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            # Three columns
            {'type': 'text', 'text': 'Strategic\nIntelligence',
             'x': inch(0.8), 'y': inch(2.8), 'w': inch(2.5), 'h': inch(0.6),
             'font_size': 18, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Insights your team\nhasn\'t seen yet',
             'x': inch(0.8), 'y': inch(3.5), 'w': inch(2.5), 'h': inch(0.5),
             'font_size': 13, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(0.8), 'y': inch(2.6), 'w': inch(2.5), 'h': pt(2), 'fill': CE_RED},
            
            {'type': 'text', 'text': 'Parallel\nProduction',
             'x': inch(3.8), 'y': inch(2.8), 'w': inch(2.5), 'h': inch(0.6),
             'font_size': 18, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': '8 AI agents working\nsimultaneously',
             'x': inch(3.8), 'y': inch(3.5), 'w': inch(2.5), 'h': inch(0.5),
             'font_size': 13, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(3.8), 'y': inch(2.6), 'w': inch(2.5), 'h': pt(2), 'fill': CE_RED},

            {'type': 'text', 'text': 'Cross-Market\nIntelligence',
             'x': inch(6.8), 'y': inch(2.8), 'w': inch(2.5), 'h': inch(0.6),
             'font_size': 18, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'True localization,\nnot translation',
             'x': inch(6.8), 'y': inch(3.5), 'w': inch(2.5), 'h': inch(0.5),
             'font_size': 13, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(6.8), 'y': inch(2.6), 'w': inch(2.5), 'h': pt(2), 'fill': CE_RED},
        ]
    },
    # Slide 4: The Operators
    {
        'id': 'bw_slide_4', 'bg': CE_WHITE,
        'elements': [
            {'type': 'text', 'text': 'THE OPERATORS',
             'x': inch(0.8), 'y': inch(0.5), 'w': inch(4), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Market veterans building the future',
             'x': inch(0.8), 'y': inch(0.9), 'w': inch(8), 'h': inch(0.5),
             'font_size': 28, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            # Assaf
            {'type': 'image', 'name': 'assaf',
             'x': inch(0.8), 'y': inch(1.8), 'w': inch(1.2), 'h': inch(1.2)},
            {'type': 'text', 'text': 'Assaf Dagan',
             'x': inch(2.2), 'y': inch(1.8), 'w': inch(3), 'h': inch(0.4),
             'font_size': 20, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'STRATEGY & CREATIVE',
             'x': inch(2.2), 'y': inch(2.2), 'w': inch(3), 'h': inch(0.3),
             'font_size': 10, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': '15+ years. Presidential campaigns, Fortune 500 repositions.\nWix, monday.com, eToro, Playtika, ironSource.\nBrand isn\'t decoration — it\'s the difference between a company\npeople remember and one they don\'t.',
             'x': inch(2.2), 'y': inch(2.6), 'w': inch(3.5), 'h': inch(1),
             'font_size': 11, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
            # Lukas
            {'type': 'image', 'name': 'lukas',
             'x': inch(5.5), 'y': inch(1.8), 'w': inch(1.2), 'h': inch(1.2)},
            {'type': 'text', 'text': 'Lukas Richthammer',
             'x': inch(6.9), 'y': inch(1.8), 'w': inch(3), 'h': inch(0.4),
             'font_size': 20, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'FORMER BRANDWATCH · MARTECH SAAS & AI SALES',
             'x': inch(6.9), 'y': inch(2.2), 'w': inch(3), 'h': inch(0.3),
             'font_size': 10, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Sold Brandwatch to enterprise clients across DACH.\nKnows how buyers evaluate social intelligence,\nwhat drives renewals, and where the gap between\ndata and action costs them.',
             'x': inch(6.9), 'y': inch(2.6), 'w': inch(3.5), 'h': inch(1),
             'font_size': 11, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 5: The System (agents)
    {
        'id': 'bw_slide_5', 'bg': CE_RED,
        'elements': [
            {'type': 'text', 'text': 'THE SYSTEM',
             'x': inch(0.8), 'y': inch(0.4), 'w': inch(4), 'h': inch(0.3),
             'font_size': 11, 'color': CE_WHITE, 'bold': True, 'font': 'Arial', 'alpha': 0.7},
            {'type': 'text', 'text': 'Eight agents. One system.',
             'x': inch(0.8), 'y': inch(0.8), 'w': inch(8), 'h': inch(0.5),
             'font_size': 28, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            # Row 1: 4 agents
            {'type': 'image', 'name': 'kitt',
             'x': inch(0.8), 'y': inch(1.7), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Kitt\nThe Strategist',
             'x': inch(0.8), 'y': inch(2.5), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            
            {'type': 'image', 'name': 'gerri',
             'x': inch(3.1), 'y': inch(1.7), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Gerri\nThe Conductor',
             'x': inch(3.1), 'y': inch(2.5), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},

            {'type': 'image', 'name': 'ogilvy',
             'x': inch(5.4), 'y': inch(1.7), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Ogilvy\nThe Poet',
             'x': inch(5.4), 'y': inch(2.5), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},

            {'type': 'image', 'name': 'tatiana',
             'x': inch(7.7), 'y': inch(1.7), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Tatiana\nThe Eye',
             'x': inch(7.7), 'y': inch(2.5), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},

            # Row 2: 4 agents
            {'type': 'image', 'name': 'anton',
             'x': inch(0.8), 'y': inch(3.3), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Anton\nThe Critic',
             'x': inch(0.8), 'y': inch(4.1), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},

            {'type': 'image', 'name': 'julia',
             'x': inch(3.1), 'y': inch(3.3), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Julia\nThe Scout',
             'x': inch(3.1), 'y': inch(4.1), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},

            {'type': 'image', 'name': 'jessica',
             'x': inch(5.4), 'y': inch(3.3), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Jessica\nThe Director',
             'x': inch(5.4), 'y': inch(4.1), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},

            {'type': 'image', 'name': 'thibault',
             'x': inch(7.7), 'y': inch(3.3), 'w': inch(0.7), 'h': inch(0.7)},
            {'type': 'text', 'text': 'Thibault\nThe Builder',
             'x': inch(7.7), 'y': inch(4.1), 'w': inch(1.8), 'h': inch(0.5),
             'font_size': 11, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 6: Pipeline
    {
        'id': 'bw_slide_6', 'bg': CE_WHITE,
        'elements': [
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(0.8), 'y': inch(0.6), 'w': inch(0.4), 'h': pt(3), 'fill': CE_RED},
            {'type': 'text', 'text': 'HOW IT WORKS',
             'x': inch(1.4), 'y': inch(0.5), 'w': inch(4), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Five phases. One pipeline.',
             'x': inch(0.8), 'y': inch(1.2), 'w': inch(8), 'h': inch(0.5),
             'font_size': 28, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            # 5 steps as numbered blocks
            {'type': 'text', 'text': '01',
             'x': inch(0.8), 'y': inch(2.2), 'w': inch(0.5), 'h': inch(0.4),
             'font_size': 14, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Data Extraction\nPull structured audience intelligence from Brandwatch',
             'x': inch(1.4), 'y': inch(2.2), 'w': inch(3), 'h': inch(0.5),
             'font_size': 12, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': '02',
             'x': inch(0.8), 'y': inch(2.9), 'w': inch(0.5), 'h': inch(0.4),
             'font_size': 14, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Strategic Analysis\nMap pain points to positioning opportunities',
             'x': inch(1.4), 'y': inch(2.9), 'w': inch(3), 'h': inch(0.5),
             'font_size': 12, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': '03',
             'x': inch(0.8), 'y': inch(3.6), 'w': inch(0.5), 'h': inch(0.4),
             'font_size': 14, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Campaign Architecture\nMessaging, tone, and channel strategy per segment',
             'x': inch(1.4), 'y': inch(3.6), 'w': inch(3), 'h': inch(0.5),
             'font_size': 12, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': '04',
             'x': inch(5.2), 'y': inch(2.2), 'w': inch(0.5), 'h': inch(0.4),
             'font_size': 14, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Asset Production\nParallel creation of production-ready deliverables',
             'x': inch(5.8), 'y': inch(2.2), 'w': inch(3.5), 'h': inch(0.5),
             'font_size': 12, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': '05',
             'x': inch(5.2), 'y': inch(2.9), 'w': inch(0.5), 'h': inch(0.4),
             'font_size': 14, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            {'type': 'text', 'text': 'Multi-Region Scaling\nLocalized strategy across all markets simultaneously',
             'x': inch(5.8), 'y': inch(2.9), 'w': inch(3.5), 'h': inch(0.5),
             'font_size': 12, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 7: Value for Brandwatch
    {
        'id': 'bw_slide_7', 'bg': CE_BLACK,
        'elements': [
            {'type': 'text', 'text': 'THE VALUE FOR BRANDWATCH',
             'x': inch(0.8), 'y': inch(0.5), 'w': inch(6), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            # 4 value props in 2x2 grid
            {'type': 'text', 'text': 'Stickiness',
             'x': inch(0.8), 'y': inch(1.3), 'w': inch(4), 'h': inch(0.4),
             'font_size': 22, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Brandwatch becomes indispensable because\nit doesn\'t just report — it responds. Churn drops.',
             'x': inch(0.8), 'y': inch(1.8), 'w': inch(4), 'h': inch(0.6),
             'font_size': 13, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': 'New Revenue',
             'x': inch(5.2), 'y': inch(1.3), 'w': inch(4), 'h': inch(0.4),
             'font_size': 22, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Creative layer as premium tier. $50K–$150K/year\nper client on top of existing subscription.',
             'x': inch(5.2), 'y': inch(1.8), 'w': inch(4), 'h': inch(0.6),
             'font_size': 13, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': 'Category Creation',
             'x': inch(0.8), 'y': inch(3.0), 'w': inch(4), 'h': inch(0.4),
             'font_size': 22, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'No social intelligence platform does this.\nOwn "social intelligence to social action" as a category.',
             'x': inch(0.8), 'y': inch(3.5), 'w': inch(4), 'h': inch(0.6),
             'font_size': 13, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': 'Agency Disintermediation',
             'x': inch(5.2), 'y': inch(3.0), 'w': inch(4), 'h': inch(0.4),
             'font_size': 22, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Brands pay Brandwatch for data AND an agency to\nact on it. Offer both — the agency becomes optional.',
             'x': inch(5.2), 'y': inch(3.5), 'w': inch(4), 'h': inch(0.6),
             'font_size': 13, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 8: Partnership Models
    {
        'id': 'bw_slide_8', 'bg': CE_WHITE,
        'elements': [
            {'type': 'shape', 'shape': 'RECTANGLE',
             'x': inch(0.8), 'y': inch(0.6), 'w': inch(0.4), 'h': pt(3), 'fill': CE_RED},
            {'type': 'text', 'text': 'PARTNERSHIP MODELS',
             'x': inch(1.4), 'y': inch(0.5), 'w': inch(4), 'h': inch(0.4),
             'font_size': 11, 'color': CE_RED, 'bold': True, 'font': 'Arial'},
            # 3 columns
            {'type': 'text', 'text': 'A',
             'x': inch(0.8), 'y': inch(1.5), 'w': inch(0.5), 'h': inch(0.5),
             'font_size': 32, 'color': CE_RED, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Technology Partnership',
             'x': inch(0.8), 'y': inch(2.1), 'w': inch(2.5), 'h': inch(0.4),
             'font_size': 16, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'CE\'s creative engine integrated as a Brandwatch premium feature. Revenue share. CE maintains the system, Brandwatch provides data + distribution.',
             'x': inch(0.8), 'y': inch(2.6), 'w': inch(2.5), 'h': inch(1.2),
             'font_size': 12, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': 'B',
             'x': inch(3.7), 'y': inch(1.5), 'w': inch(0.5), 'h': inch(0.5),
             'font_size': 32, 'color': CE_RED, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'White-Label',
             'x': inch(3.7), 'y': inch(2.1), 'w': inch(2.5), 'h': inch(0.4),
             'font_size': 16, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'CE runs under the Brandwatch brand. "Brandwatch Creative Intelligence." Deeper integration. Maximum brand leverage.',
             'x': inch(3.7), 'y': inch(2.6), 'w': inch(2.5), 'h': inch(1.2),
             'font_size': 12, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},

            {'type': 'text', 'text': 'C',
             'x': inch(6.6), 'y': inch(1.5), 'w': inch(0.5), 'h': inch(0.5),
             'font_size': 32, 'color': CE_RED, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Acquisition',
             'x': inch(6.6), 'y': inch(2.1), 'w': inch(2.5), 'h': inch(0.4),
             'font_size': 16, 'color': CE_BLACK, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Full integration into the product roadmap. Maximum commitment. Biggest upside for both.',
             'x': inch(6.6), 'y': inch(2.6), 'w': inch(2.5), 'h': inch(1.2),
             'font_size': 12, 'color': CE_GREY, 'bold': False, 'font': 'Arial'},
        ]
    },
    # Slide 9: The Ask
    {
        'id': 'bw_slide_9', 'bg': CE_RED,
        'elements': [
            {'type': 'text', 'text': 'THE ASK',
             'x': inch(0.8), 'y': inch(0.5), 'w': inch(4), 'h': inch(0.3),
             'font_size': 11, 'color': CE_WHITE, 'bold': True, 'font': 'Arial', 'alpha': 0.7},
            {'type': 'text', 'text': 'What would Brandwatch look like\nif every insight came with a\nready-to-deploy creative response?',
             'x': inch(0.8), 'y': inch(1.2), 'w': inch(8), 'h': inch(1.5),
             'font_size': 32, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'A 60-minute conversation with Brandwatch product leadership.\n\nWe\'ll bring a live demonstration — real brand data, processed through\nCE\'s pipeline, with finished campaign assets.\n\nNot a deck. The actual output.',
             'x': inch(0.8), 'y': inch(3.2), 'w': inch(7), 'h': inch(1.5),
             'font_size': 16, 'color': CE_WHITE, 'bold': False, 'font': 'Arial', 'alpha': 0.85},
        ]
    },
    # Slide 10: Contact
    {
        'id': 'bw_slide_10', 'bg': CE_BLACK,
        'elements': [
            {'type': 'text', 'text': 'LET\'S TALK',
             'x': inch(0.8), 'y': inch(1.5), 'w': inch(8), 'h': inch(0.8),
             'font_size': 42, 'color': CE_WHITE, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Assaf Dagan\nassaf@curiousendeavor.com',
             'x': inch(0.8), 'y': inch(2.8), 'w': inch(4), 'h': inch(0.6),
             'font_size': 16, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'Lukas Richthammer',
             'x': inch(5.2), 'y': inch(2.8), 'w': inch(4), 'h': inch(0.6),
             'font_size': 16, 'color': CE_LIGHT, 'bold': False, 'font': 'Arial'},
            {'type': 'text', 'text': 'curiousendeavor.com/brandwatch-v2',
             'x': inch(0.8), 'y': inch(4.2), 'w': inch(5), 'h': inch(0.4),
             'font_size': 13, 'color': CE_RED, 'bold': False, 'font': 'Arial'},
        ]
    },
]

# Build requests for all slides
all_requests = []

# First update the existing slide (s0)
first_slide_id = pres['slides'][0]['objectId']

# Set background for first slide
all_requests.append({
    'updatePageProperties': {
        'objectId': first_slide_id,
        'pageProperties': {
            'pageBackgroundFill': {
                'solidFill': {'color': {'rgbColor': SLIDE_DEFS[0]['bg']}}
            }
        },
        'fields': 'pageBackgroundFill'
    }
})

# Create remaining slides
for i, sd in enumerate(SLIDE_DEFS):
    if i == 0:
        continue
    all_requests.append({
        'createSlide': {
            'objectId': sd['id'],
            'insertionIndex': i,
            'slideLayoutReference': {'predefinedLayout': 'BLANK'}
        }
    })

# Execute slide creation
slides_service.presentations().batchUpdate(
    presentationId=PRESENTATION_ID,
    body={'requests': all_requests}
).execute()
print("Created blank slides")

# Set backgrounds for all new slides
bg_requests = []
for i, sd in enumerate(SLIDE_DEFS):
    if i == 0:
        continue
    bg_requests.append({
        'updatePageProperties': {
            'objectId': sd['id'],
            'pageProperties': {
                'pageBackgroundFill': {
                    'solidFill': {'color': {'rgbColor': sd['bg']}}
                }
            },
            'fields': 'pageBackgroundFill'
        }
    })

if bg_requests:
    slides_service.presentations().batchUpdate(
        presentationId=PRESENTATION_ID,
        body={'requests': bg_requests}
    ).execute()
    print("Set backgrounds")

# Now add elements to each slide
for i, sd in enumerate(SLIDE_DEFS):
    slide_obj_id = first_slide_id if i == 0 else sd['id']
    el_requests = []
    
    for j, el in enumerate(sd['elements']):
        obj_id = f"{sd['id']}_el{j}"
        
        if el['type'] == 'text':
            el_requests.append({
                'createShape': {
                    'objectId': obj_id,
                    'shapeType': 'TEXT_BOX',
                    'elementProperties': {
                        'pageObjectId': slide_obj_id,
                        'size': {
                            'width': {'magnitude': el['w'], 'unit': 'EMU'},
                            'height': {'magnitude': el['h'], 'unit': 'EMU'}
                        },
                        'transform': {
                            'scaleX': 1, 'scaleY': 1,
                            'translateX': el['x'], 'translateY': el['y'],
                            'unit': 'EMU'
                        }
                    }
                }
            })
            el_requests.append({
                'insertText': {
                    'objectId': obj_id,
                    'text': el['text']
                }
            })
            style = {
                'foregroundColor': {'opaqueColor': {'rgbColor': el['color']}},
                'fontSize': {'magnitude': el['font_size'], 'unit': 'PT'},
                'bold': el.get('bold', False),
                'fontFamily': el.get('font', 'Arial'),
            }
            el_requests.append({
                'updateTextStyle': {
                    'objectId': obj_id,
                    'style': style,
                    'textRange': {'type': 'ALL'},
                    'fields': 'foregroundColor,fontSize,bold,fontFamily'
                }
            })
            
        elif el['type'] == 'shape':
            el_requests.append({
                'createShape': {
                    'objectId': obj_id,
                    'shapeType': el['shape'],
                    'elementProperties': {
                        'pageObjectId': slide_obj_id,
                        'size': {
                            'width': {'magnitude': el['w'], 'unit': 'EMU'},
                            'height': {'magnitude': el['h'], 'unit': 'EMU'}
                        },
                        'transform': {
                            'scaleX': 1, 'scaleY': 1,
                            'translateX': el['x'], 'translateY': el['y'],
                            'unit': 'EMU'
                        }
                    }
                }
            })
            el_requests.append({
                'updateShapeProperties': {
                    'objectId': obj_id,
                    'shapeProperties': {
                        'shapeBackgroundFill': {
                            'solidFill': {'color': {'rgbColor': el['fill']}}
                        },
                        'outline': {'propertyState': 'NOT_RENDERED'}
                    },
                    'fields': 'shapeBackgroundFill,outline'
                }
            })
            
        elif el['type'] == 'image':
            name = el['name']
            if name in images:
                el_requests.append({
                    'createImage': {
                        'objectId': obj_id,
                        'url': images[name],
                        'elementProperties': {
                            'pageObjectId': slide_obj_id,
                            'size': {
                                'width': {'magnitude': el['w'], 'unit': 'EMU'},
                                'height': {'magnitude': el['h'], 'unit': 'EMU'}
                            },
                            'transform': {
                                'scaleX': 1, 'scaleY': 1,
                                'translateX': el['x'], 'translateY': el['y'],
                                'unit': 'EMU'
                            }
                        }
                    }
                })
    
    if el_requests:
        try:
            slides_service.presentations().batchUpdate(
                presentationId=PRESENTATION_ID,
                body={'requests': el_requests}
            ).execute()
            print(f"  Slide {i}: {len(el_requests)} elements")
        except Exception as e:
            print(f"  Slide {i} ERROR: {e}")
    
    time.sleep(0.2)

print(f"\nDeck ready: https://docs.google.com/presentation/d/{PRESENTATION_ID}/edit")
