#!/usr/bin/env python3
"""
Simple import script to add Brand content to Notion page.
"""

import json
import requests
import os

# Configuration
NOTION_KEY_PATH = "/home/clawd/secrets/notion/api_key"
NOTION_API = "https://api.notion.com/v1"
NOTION_VERSION = "2022-06-28"
TARGET_PAGE_ID = "306330c2-8646-812a-bb8b-c6b39d28492a"

def get_notion_key():
    with open(NOTION_KEY_PATH) as f:
        return f.read().strip()

def notion_headers():
    return {
        "Authorization": f"Bearer {get_notion_key()}",
        "Notion-Version": NOTION_VERSION,
        "Content-Type": "application/json"
    }

def add_test_content():
    """Add the main content structure first."""
    url = f"{NOTION_API}/blocks/{TARGET_PAGE_ID}/children"
    
    blocks = [
        {
            "object": "block",
            "type": "heading_1",
            "heading_1": {
                "rich_text": [{"text": {"content": "Brand & Content System Architecture Playbook"}}]
            }
        },
        {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
                "rich_text": [{"text": {"content": "Complete Implementation Guide for AI-Powered Brand Systems"}, "annotations": {"italic": True}}]
            }
        },
        {
            "object": "block",
            "type": "divider",
            "divider": {}
        },
        {
            "object": "block",
            "type": "heading_2",
            "heading_2": {
                "rich_text": [{"text": {"content": "📋 Project Overview"}}]
            }
        },
        {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
                "rich_text": [
                    {"text": {"content": "Purpose: "}, "annotations": {"bold": True}},
                    {"text": {"content": "Create scalable, AI-enhanced brand and content systems that preserve human creativity, cultural nuance, and authentic brand voice while leveraging automation for efficiency."}}
                ]
            }
        },
        {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
                "rich_text": [
                    {"text": {"content": "Target Audience: "}, "annotations": {"bold": True}},
                    {"text": {"content": "Brand strategists, content teams, AI implementation specialists, creative directors"}}
                ]
            }
        },
        {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
                "rich_text": [
                    {"text": {"content": "Deliverable: "}, "annotations": {"bold": True}},
                    {"text": {"content": "Production-ready system architecture with implementation roadmap"}}
                ]
            }
        }
    ]
    
    payload = {"children": blocks}
    response = requests.patch(url, headers=notion_headers(), json=payload)
    
    print(f"Response status: {response.status_code}")
    if response.status_code == 200:
        print("✅ Successfully added basic content structure")
        return True
    else:
        print(f"❌ Error: {response.text}")
        return False

def main():
    print("🚀 Simple Notion Import Test")
    print("=" * 40)
    
    # Test basic content addition
    print("Adding basic content structure...")
    if add_test_content():
        print("\n🎉 Basic content added successfully!")
        print("Now proceeding with full content import...")
        
        # If basic test works, run the full import
        os.system("python3 import_brand_content_to_notion.py")
    else:
        print("❌ Basic test failed. Check API permissions.")

if __name__ == "__main__":
    main()