import os
import requests
import json
from dotenv import load_dotenv

load_dotenv(dotenv_path="/home/node/clawd/.env")

NOTION_TOKEN = os.getenv("NOTION_API_KEY")
HEADERS = {
    "Authorization": f"Bearer {NOTION_TOKEN}",
    "Content-Type": "application/json",
    "Notion-Version": "2022-06-28"
}

# IDs from yesterday
TASKS = {
    "Pains Gains Vertical": "2ff88f42-8544-8050-8245-c3bb852058f4",
    "Segmentierung Bestand": "2ff88f42-8544-808f-862b-c30ab2f29783",
    "Matrixmultiplikation": "2ff88f42-8544-8079-a23e-c248e35b09a0"
}

UPDATES = {
    "Pains Gains Vertical": "Update 17.02.: ✅ Entwurf in Notion finalisiert und detailliert (inkl. Hygiene-Fokus). Bereit für Review am Freitag.",
    "Segmentierung Bestand": "Update 17.02.: ✅ Company Explorer Schema erweitert (V2). Bereit für Excel-Import.",
    "Matrixmultiplikation": "Update 17.02.: ✅ Logik '3+1' (Prio Produkt + Sekundär bei Ops-Rolle) in Datenstruktur abgebildet."
}

def append_block(page_id, text):
    url = f"https://api.notion.com/v1/blocks/{page_id}/children"
    payload = {
        "children": [
            {
                "object": "block",
                "type": "paragraph",
                "paragraph": {
                    "rich_text": [
                        {
                            "type": "text",
                            "text": {
                                "content": text,
                                "link": None
                            },
                            "annotations": {
                                "bold": True, # Make it stand out
                                "italic": False,
                                "strikethrough": False,
                                "underline": False,
                                "code": False,
                                "color": "default"
                            }
                        }
                    ]
                }
            }
        ]
    }
    resp = requests.patch(url, headers=HEADERS, json=payload)
    if resp.status_code == 200:
        print(f"✅ Appended to {page_id}")
    else:
        print(f"❌ Error {page_id}: {resp.text}")

if __name__ == "__main__":
    for name, page_id in TASKS.items():
        if name in UPDATES:
            append_block(page_id, UPDATES[name])
