"""Seed flow_items with proper UTF-8 via HTTP API."""
import urllib.request, json

BASE = "http://localhost:5000/api/dashboard/flow"

# Delete all existing
resp = urllib.request.urlopen(BASE)
data = json.loads(resp.read())
for item in data.get("items", []):
    req = urllib.request.Request(f"{BASE}/{item['id']}", method="DELETE")
    urllib.request.urlopen(req)
print("Cleared all existing flow items")

items = [
    {"id":"f01","title":"Kh\u00e1ch g\u1eedi tin nh\u1eafn","description":"Kh\u00e1ch h\u00e0ng nh\u1eadp c\u00e2u h\u1ecfi qua chatbot widget tr\u00ean web/app","category":"input","parent_id":None,"sort_order":1,"icon":"\ud83d\udcac"},
    {"id":"f02","title":"API Gateway","description":"FastAPI nh\u1eadn request, x\u00e1c th\u1ef1c, rate limit","category":"process","parent_id":None,"sort_order":2,"icon":"\ud83d\udd0c"},
    {"id":"f03","title":"Ki\u1ec3m tra cache","description":"Tra b\u1ed9 nh\u1edb t\u1ea1m \u2014 c\u00e2u h\u1ecfi n\u00e0y \u0111\u00e3 \u0111\u01b0\u1ee3c h\u1ecfi ch\u01b0a?","category":"process","parent_id":None,"sort_order":3,"icon":"\u26a1"},
    {"id":"f04","title":"L\u1ea5y l\u1ecbch s\u1eed + h\u1ed3 s\u01a1 kh\u00e1ch","description":"10 tin nh\u1eafn g\u1ea7n nh\u1ea5t + h\u1ed3 s\u01a1 d\u00e0i h\u1ea1n (size, s\u1edf th\u00edch)","category":"process","parent_id":None,"sort_order":4,"icon":"\ud83d\udcbe"},
    {"id":"f05","title":"AI Agent suy ngh\u0129","description":"Gemini ph\u00e2n t\u00edch \u00fd \u0111\u1ecbnh, quy\u1ebft \u0111\u1ecbnh c\u1ea7n tra c\u1ee9u g\u00ec","category":"process","parent_id":None,"sort_order":5,"icon":"\ud83e\udde0"},
    {"id":"f06","title":"Product Search (Vector)","description":"T\u00ecm s\u1ea3n ph\u1ea9m b\u1eb1ng semantic search + SQL filters","category":"tool","parent_id":"f05","sort_order":6,"icon":"\ud83d\udd0d"},
    {"id":"f07","title":"Stock Check","description":"Ki\u1ec3m tra t\u1ed3n kho realtime qua API Magento","category":"tool","parent_id":"f05","sort_order":7,"icon":"\ud83d\udce6"},
    {"id":"f08","title":"Knowledge Base","description":"Tra ch\u00ednh s\u00e1ch \u0111\u1ed5i tr\u1ea3, khuy\u1ebfn m\u00e3i, th\u00f4ng tin c\u1eeda h\u00e0ng","category":"tool","parent_id":"f05","sort_order":8,"icon":"\ud83d\udcda"},
    {"id":"f09","title":"Streaming Response","description":"Tr\u1ea3 l\u1eddi t\u1eebng ch\u1eef nh\u01b0 ChatGPT, k\u00e8m product cards","category":"output","parent_id":None,"sort_order":9,"icon":"\ud83d\udce1"},
    {"id":"f10","title":"Background Tasks","description":"L\u01b0u l\u1ecbch s\u1eed, c\u1eadp nh\u1eadt h\u1ed3 s\u01a1 kh\u00e1ch, cache, log Langfuse","category":"output","parent_id":None,"sort_order":10,"icon":"\u2699\ufe0f"},
    {"id":"f11","title":"Langfuse Trace","description":"Log observability: latency, tokens, cost, scores","category":"monitor","parent_id":None,"sort_order":11,"icon":"\ud83d\udcca"},
]

for item in items:
    body = json.dumps(item).encode("utf-8")
    req = urllib.request.Request(BASE, data=body, headers={"Content-Type":"application/json"}, method="POST")
    urllib.request.urlopen(req)

print(f"Seeded {len(items)} flow items OK")
