#!/usr/bin/env python3
"""
Improved startup script that shows model cache information
to help avoid unnecessary downloads.
"""

import sys
import os
from pathlib import Path

# Add the app directory to the Python path
sys.path.insert(0, str(Path(__file__).parent))

from app.model_cache import setup_model_cache, check_cached_models
from app.config import YOLO_MODEL, CLIP_MODEL

def show_startup_info():
    """Show startup information including cache status"""
    print("=" * 70)
    print("🏠 Property Image Verification System")
    print("=" * 70)
    print()
    
    # Set up caching
    print("📦 Setting up model cache...")
    cache_dir = setup_model_cache()
    cache_info = check_cached_models()
    
    print(f"📍 Cache directory: {cache_info['cache_dir']}")
    print(f"💾 Cache size: {cache_info['cache_size_mb']} MB")
    print(f"📁 Cached models: {cache_info['cached_models']}")
    print()
    
    # Show what models will be loaded
    print("🤖 AI Models Configuration:")
    print(f"   • YOLO Model: {YOLO_MODEL}")
    print(f"   • CLIP Model: {CLIP_MODEL}")
    print()
    
    # Show download expectations
    if cache_info['cache_size_mb'] < 100:  # Less than 100MB cached
        print("⚠️  WARNING: Models not fully cached yet!")
        print("   First run will download ~605MB of model files:")
        print("   • YOLOv8n: ~6MB")
        print("   • CLIP model: ~350MB + dependencies")
        print("   • This is a ONE-TIME download - subsequent runs will be instant!")
        print()
        print("⏳ Expected first startup time: 2-3 minutes")
        print("⚡ Expected subsequent startups: ~10 seconds")
    else:
        print("✅ Models are cached! Startup should be fast (~10 seconds)")
        print("📈 No downloads needed - using cached models")
    
    print()
    print("🚀 Starting server...")
    print("=" * 70)
    print()

if __name__ == "__main__":
    show_startup_info()
    
    # Start the server
    import uvicorn
    from app.config import HOST, PORT
    
    uvicorn.run(
        "app.main:app",
        host=HOST,
        port=PORT,
        reload=True,
        log_level="info"
    )