import clawd_notion as notion
import sys
import json

def main():
    if len(sys.argv) < 2:
        print("Usage: python list_tasks.py <project_id>")
        return

    project_id = sys.argv[1]
    db_id = notion.find_db("Tasks [UT]")
    
    tasks = notion.query_db(db_id, {
        "property": "Project",
        "relation": {"contains": project_id}
    })
    
    # Filter out done tasks if needed, or sort
    # For now, just list all linked
    
    print(f"Tasks für Projekt {project_id}:")
    for i, t in enumerate(tasks):
        status = t["properties"].get("Status", {}).get("status", {}).get("name", "No Status")
        if status == "Done": continue
        print(f"{i+1}. [{status}] {notion.get_title(t)} (ID: {t['id']})")

if __name__ == "__main__":
    main()
