#!/usr/bin/env python3
"""
Test script to verify catalog filtering by vehicle_class.
Run inside sf_api container: docker compose exec sf_api python /opt/docker/dev/service_finder/test_catalog_filter.py
"""
import asyncio
import sys
import os
sys.path.insert(0, '/app/backend')

from app.db.session import async_sessionmaker
from app.services.asset_service import AssetService

async def test_catalog_filter():
    async with async_sessionmaker() as session:
        async with session.begin():
            # Get first make
            makes = await AssetService.get_makes(session)
            if not makes:
                print("No makes found in database")
                return
            test_make = makes[0]
            print(f"Testing with make: {test_make}")
            
            # Get models without filter
            models_all = await AssetService.get_models(session, test_make)
            print(f"All models ({len(models_all)}): {models_all[:3]}...")
            
            # Get models with vehicle_class filter (passenger_car)
            models_filtered = await AssetService.get_models(session, test_make, 'passenger_car')
            print(f"Filtered by 'passenger_car' ({len(models_filtered)}): {models_filtered[:3]}...")
            
            # Get models with vehicle_class filter (motorcycle)
            models_motorcycle = await AssetService.get_models(session, test_make, 'motorcycle')
            print(f"Filtered by 'motorcycle' ({len(models_motorcycle)}): {models_motorcycle[:3]}...")
            
            # Compare counts
            if models_filtered:
                print("✓ Filtering by vehicle_class works")
                if len(models_filtered) <= len(models_all):
                    print("✓ Filtered count is less or equal (good)")
                else:
                    print("⚠ Filtered count is greater (unexpected)")
            else:
                print("⚠ No models found with filter (maybe no passenger_car vehicles for this make)")

if __name__ == "__main__":
    asyncio.run(test_catalog_filter())