#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import json
from pathlib import Path

BASE_DIR = Path(r"c:\Projects\KieuStory")
sys.path.insert(0, str(BASE_DIR / "05_Production_Pipeline"))
import production_orchestrator as po

shots = po.get_all_shots("ep01")
banana_file = po.BANANA_PROMPTS_FILE
banana_data = json.loads(banana_file.read_text(encoding="utf-8")) if banana_file.exists() else {}

missing_shots = [
    "ep01_scene01_shot02", "ep01_scene01_shot03", "ep01_scene01_shot04", "ep01_scene01_shot05",
    "ep01_scene01_shot06", "ep01_scene01_shot07", "ep01_scene01_shot09", "ep01_scene01_shot10",
    "ep01_scene01_shot11", "ep01_scene01_shot12", "ep01_scene01_shot13", "ep01_scene01_shot14",
    "ep01_scene01_shot15", "ep01_scene01_shot16", "ep01_scene01_shot17", "ep01_scene01_shot18",
    "ep01_scene01_shot19", "ep01_scene01_shot20", "ep01_scene01_shot21",
    "ep01_scene04_shot01", "ep01_scene05_shot07", "ep01_scene05_shot10",
    "ep01_scene06_shot01", "ep01_scene06_shot02", "ep01_scene08_shot01"
]

print(f"Total missing shots to investigate: {len(missing_shots)}")
for sid in missing_shots:
    s = shots.get(sid, {})
    b = po.get_banana_prompt_data(sid)
    print(f"\n=== {sid} ===")
    print(f"  Title:      {s.get('scene_title')}")
    print(f"  Motion:     {s.get('motion_prompt', '')[:80]}...")
    print(f"  Shot Anchor:{s.get('character_anchor')}")
    print(f"  Asset Ref:  {s.get('character_asset_ref')}")
    print(f"  Ref SF:     {s.get('reference_start_frame')}")
    if b:
        print(f"  Banana Key: FOUND -> anchor={b.get('character_anchor')}, prompt={b.get('prompt', '')[:60]}...")
    else:
        print(f"  Banana Key: NOT FOUND")

# Also let's check what keys exist in BANANA_PROMPTS_FILE
print("\n=== BANANA PROMPT KEYS SAMPLE ===")
for k in list(banana_data.keys())[:10]:
    val = banana_data[k]
    if isinstance(val, dict):
        print(f"Dict key: {k} (len {len(val)})")
    else:
        print(f"Other key: {k}")
if "ep01_start_frames" in banana_data:
    print("ep01_start_frames subkeys:", list(banana_data["ep01_start_frames"].keys())[:15])

# Also check scene01 in banana prompts
print("\n=== SCENE01 SHOTS IN BANANA PROMPTS ===")
sc01_keys = [k for k in banana_data.get("ep01_start_frames", {}).keys() if "scene01" in k]
print(f"Scene 01 keys in ep01_start_frames: {sc01_keys}")
all_b_sc01 = [k for k in banana_data.keys() if "scene01" in k]
print(f"Direct scene01 keys in banana_data root: {all_b_sc01}")
