"""
Notion — Query Database Demo
=============================
A minimal, ready-to-run example of querying a Notion database.

Get an API key (free):
    1. Go to https://www.notion.so/my-integrations and click
       "New integration"; copy the "Internal Integration Secret".
    2. Open the Notion database you want to read, click the "..." menu ->
       Connections -> add your integration (so it has access).
    3. The database ID is the 32-char hash in the database URL.

Setup:
    pip install requests
    export NOTION_API_KEY="secret_..."
    export NOTION_DATABASE_ID="..."

Run:
    python notion_demo.py
"""

import os
import requests


def query_database() -> list:
    """Return the raw result rows from a Notion database query."""
    db_id = os.environ.get("NOTION_DATABASE_ID")
    response = requests.post(
        f"https://api.notion.com/v1/databases/{db_id}/query",
        headers={
            "Authorization": f"Bearer {os.environ.get('NOTION_API_KEY')}",
            "Notion-Version": "2022-06-28",
        },
    )
    response.raise_for_status()
    return response.json()["results"]


if __name__ == "__main__":
    rows = query_database()
    print(f"Found {len(rows)} rows")
