#!/usr/bin/env python3
"""
Test script to verify shapefile overlay API returns correct bbox data
"""

import requests
import json

def test_shapefile_api():
    """Test /api/overlay/shapefiles endpoint"""
    print("Testing /api/overlay/shapefiles endpoint...")
    
    try:
        response = requests.get('http://localhost:8000/api/overlay/shapefiles')
        
        if response.status_code == 200:
            data = response.json()
            print(f"\n✅ API Response successful")
            print(f"Total shapefiles: {data.get('count', 0)}")
            
            if data.get('shapefiles'):
                print("\n📋 Shapefile details:")
                for idx, shp in enumerate(data['shapefiles'], 1):
                    print(f"\n{idx}. {shp.get('filename')}")
                    print(f"   Path: {shp.get('path')}")
                    print(f"   CRS: {shp.get('crs')}")
                    print(f"   Features: {shp.get('feature_count')}")
                    print(f"   Bbox: {shp.get('bbox')}")
                    
                    # Verify bbox format
                    bbox = shp.get('bbox')
                    if bbox and len(bbox) == 4:
                        print(f"   ✅ Bbox format valid: [minLon, minLat, maxLon, maxLat]")
                    else:
                        print(f"   ❌ Bbox format invalid or missing!")
            else:
                print("\n⚠️ No shapefiles found")
        else:
            print(f"\n❌ API returned status code: {response.status_code}")
            print(f"Response: {response.text}")
            
    except requests.exceptions.ConnectionError:
        print("\n❌ Cannot connect to API server. Is it running on localhost:8000?")
    except Exception as e:
        print(f"\n❌ Error: {e}")

if __name__ == "__main__":
    test_shapefile_api()
