#!/usr/bin/env python3
"""Writes example-plan.json (first draft of a fictional app, Postwell) and example-plan-fixed.json."""
import copy
import json
from pathlib import Path

ANA = {"id": "UCanaFict0000000000000001", "label": "Ana's cooking channel (fictional)"}
LEO = {"id": "UCleoFict0000000000000002", "label": "Leo's software channel (fictional)"}
APP = {"name": "Postwell (fictional)", "review_date": "2026-11-30",
       "requested_scopes": ["youtube.upload"], "features": ["upload", "thumbnails", "playlists"],
       "oauth": {"user_type": "external", "publishing_status": "testing", "verification": "not_submitted"},
       "ui": {"privacy_choice_shown": False, "upload_notice_shown": False}}
LONG_TITLE = "Ana's full one-pot lentil stew recipe for busy weeknights, with a shopping list, timings and three easy variations"
TAGS = ["lentil stew", "one pot recipe", "weeknight dinner", "easy vegan dinner", "high protein vegan meal",
        "budget recipes", "meal prep ideas", "healthy comfort food", "pantry recipes", "cooking for beginners",
        "plant based dinner", "lentil recipes", "quick dinner ideas", "batch cooking", "winter soups",
        "family dinner ideas", "how to cook lentils", "vegetarian stew", "easy dinner recipes", "Ana cooks", "cheap meals",
        "lentil stew without tomatoes", "one pot lentil soup", "slow cooker lentils", "lentil stew with spinach", "dinner under 5 euros", "student recipes"]
draft = {"app": APP, "uploads": [
  {"id": "1-ana-lentil-recipe", "channel": dict(ANA, verified=True), "upload_at": "2026-12-01T16:00:00Z",
   "refresh_token_issued_at": "2026-11-29T10:00:00Z", "intended_format": "long",
   "video": {"file": "lentil-stew.mp4", "mime": "video/mp4", "bytes": 1840000000, "seconds": 842, "width": 3840, "height": 2160},
   "resource": {"snippet": {"title": LONG_TITLE, "description": "Ingredients and steps in the video. Shopping list: postwell.example/lentils", "tags": TAGS, "categoryId": "26"},
                "status": {}},
   "origin": {"generated_by": "person"}},
  {"id": "2-ana-knife-short", "channel": ANA, "upload_at": "2026-12-01T18:00:00Z",
   "refresh_token_issued_at": "2026-11-29T10:00:00Z", "intended_format": "short",
   "video": {"file": "knife-tip.mp4", "mime": "video/mp4", "bytes": 48000000, "seconds": 45, "width": 1920, "height": 1080},
   "resource": {"snippet": {"title": "One knife trick for onions #shorts", "categoryId": "26"},
                "status": {"privacyStatus": "public", "selfDeclaredMadeForKids": False},
                "paidProductPlacementDetails": {"hasPaidProductPlacement": False}},
   "thumbnail": {"file": "knife-tip.webp", "format": "webp", "bytes": 310000, "width": 1080, "height": 1920},
   "origin": {"generated_by": "person"}},
  {"id": "3-leo-api-webinar", "channel": dict(LEO, verified=False), "upload_at": "2026-12-02T09:00:00Z",
   "refresh_token_issued_at": "2026-11-28T09:00:00Z", "intended_format": "long",
   "video": {"file": "webinar.mov", "mime": "video/quicktime", "bytes": 6200000000, "seconds": 3120, "width": 1920, "height": 1080},
   "resource": {"snippet": {"title": "Designing a public API: live webinar", "description": "Slides: <b>postwell.example/webinar</b>", "categoryId": "28"},
                "status": {"privacyStatus": "public", "publishAt": "2026-12-03T17:00:00Z", "selfDeclaredMadeForKids": False},
                "paidProductPlacementDetails": {"hasPaidProductPlacement": False}},
   "origin": {"generated_by": "person"}},
  {"id": "4-leo-ai-explainer", "channel": dict(LEO, verified=False), "upload_at": "2026-12-02T12:00:00Z",
   "refresh_token_issued_at": "2026-11-28T09:00:00Z", "intended_format": "long",
   "video": {"file": "explainer.mp4", "mime": "video/mp4", "bytes": 210000000, "seconds": 240, "width": 1920, "height": 1080},
   "resource": {"snippet": {"title": "What an API gateway does, explained by our AI presenter", "categoryId": "28"},
                "status": {"privacyStatus": "unlisted", "selfDeclaredMadeForKids": False},
                "paidProductPlacementDetails": {"hasPaidProductPlacement": False}},
   "origin": {"generated_by": "ai_agent", "realistic_synthetic": True}},
  {"id": "5-ana-recipe-spanish", "channel": dict(ANA, verified=True), "upload_at": "2026-12-03T16:00:00Z",
   "refresh_token_issued_at": "2026-11-29T10:00:00Z", "intended_format": "long",
   "video": {"file": "gazpacho.mp4", "mime": "video/mp4", "bytes": 920000000, "seconds": 510, "width": 1920, "height": 1080},
   "resource": {"snippet": {"title": "Gazpacho in ten minutes", "categoryId": 26},
                "localizations": {"es": {"title": "Gazpacho en diez minutos", "description": "Receta completa"}},
                "status": {"privacyStatus": "private", "publishAt": "2026-12-04T08:00:00Z", "selfDeclaredMadeForKids": False},
                "paidProductPlacementDetails": {"hasPaidProductPlacement": True}},
   "origin": {"generated_by": "person"}},
  {"id": "6-leo-tips-playlist", "channel": dict(LEO, verified=False), "upload_at": "2026-12-06T10:00:00Z",
   "refresh_token_issued_at": "2026-11-28T09:00:00Z", "intended_format": "short", "playlist_id": "PLleoFictTips",
   "upload_chunk_bytes": 10000000,
   "video": {"file": "tip-12.mp4", "mime": "video/mp4", "bytes": 64000000, "seconds": 58, "width": 1080, "height": 1920},
   "resource": {"snippet": {"title": "Tip 12: return 429 with Retry-After", "categoryId": "28"},
                "status": {"privacyStatus": "public", "selfDeclaredMadeForKids": False},
                "paidProductPlacementDetails": {"hasPaidProductPlacement": False}},
   "origin": {"generated_by": "person"}}]}

fixed = copy.deepcopy(draft)
fixed["app"]["requested_scopes"] = ["youtube.force-ssl"]
fixed["app"]["features"] = ["upload", "thumbnails", "playlists", "read_status"]
fixed["app"]["oauth"] = {"user_type": "external", "publishing_status": "in_production", "verification": "verified"}
fixed["app"]["ui"] = {"privacy_choice_shown": True, "upload_notice_shown": True}
u = {x["id"]: x for x in fixed["uploads"]}
u1 = u["1-ana-lentil-recipe"]
u1["resource"]["snippet"]["title"] = "One-pot lentil stew for busy weeknights (3 variations)"
u1["resource"]["snippet"]["tags"] = TAGS[:12]
u1["resource"]["status"] = {"privacyStatus": "public", "selfDeclaredMadeForKids": False}
u1["resource"]["paidProductPlacementDetails"] = {"hasPaidProductPlacement": False}
u2 = u["2-ana-knife-short"]
u2["channel"] = dict(ANA, verified=True)
u2["video"].update({"width": 1080, "height": 1920})
u2["thumbnail"] = {"file": "knife-tip.jpg", "format": "jpg", "bytes": 420000, "width": 1080, "height": 1920}
u3 = u["3-leo-api-webinar"]
u3["channel"] = dict(LEO, verified=True)
u3["resource"]["snippet"]["description"] = "Slides: https://postwell.example/webinar"
u3["resource"]["status"]["privacyStatus"] = "private"
u4 = u["4-leo-ai-explainer"]
u4["channel"] = dict(LEO, verified=True)
u4["origin"] = {"generated_by": "ai_agent", "realistic_synthetic": True, "approved_by": "Leo (channel owner)"}
u4["resource"]["status"]["containsSyntheticMedia"] = True
u5 = u["5-ana-recipe-spanish"]
u5["resource"]["snippet"]["categoryId"] = "26"
u5["resource"]["snippet"]["defaultLanguage"] = "en"
u6 = u["6-leo-tips-playlist"]
u6["channel"] = dict(LEO, verified=True)
u6["upload_chunk_bytes"] = 16777216
here = Path(__file__).resolve().parent
for name, data in (("example-plan.json", draft), ("example-plan-fixed.json", fixed)):
    (here / name).write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
print("ok")
