"""Debug insights availability for a study."""
import sys
sys.path.insert(0, ".")
from pathlib import Path

# Test study path resolution
study_id = 'm1_mirror_cost_reduction_V9'
STUDIES_DIR = Path('studies')

# Check nested path
for topic_dir in STUDIES_DIR.iterdir():
    if topic_dir.is_dir():
        study_dir = topic_dir / study_id
        if study_dir.exists():
            print(f"Found study at: {study_dir}")
            print(f"Has 1_setup: {(study_dir / '1_setup').exists()}")
            print(f"Has 2_results: {(study_dir / '2_results').exists()}")

            # Check what insights are available
            from optimization_engine.insights import list_available_insights, get_configured_insights, recommend_insights_for_study

            print("\n--- Available insights (can_generate=True) ---")
            available = list_available_insights(study_dir)
            print(f"Count: {len(available)}")
            for a in available:
                print(f"  - {a}")

            print("\n--- Configured insights ---")
            configured = get_configured_insights(study_dir)
            print(f"Count: {len(configured)}")
            for c in configured:
                print(f"  - {c.type}: {c.name}")

            print("\n--- Recommendations ---")
            recs = recommend_insights_for_study(study_dir)
            print(f"Count: {len(recs)}")
            for r in recs:
                print(f"  - {r['type']}: {r['name']}")

            # Test individual insight can_generate
            print("\n--- Testing each insight's can_generate ---")
            from optimization_engine.insights import get_insight, list_insights

            for info in list_insights():
                insight = get_insight(info['type'], study_dir)
                if insight:
                    can = insight.can_generate()
                    print(f"  {info['type']:20} can_generate={can}")

            break
