#!/usr/bin/env python3
"""
Check specific Tods product in database
"""
import sys
import asyncio
sys.path.append('backend')

from sqlalchemy import select, func, text
from app.core.database import get_db
from app.models.products_master import ProductMaster

async def check_specific_tods():
    """Check specific Tods product"""
    print("Checking specific Tods product...")
    
    try:
        async for db in get_db():
            # Look for this specific product
            specific_query = select(ProductMaster).where(
                ProductMaster.线上宝贝名称.like('%卡其色麻花拖鞋%')
            )
            
            specific_result = await db.execute(specific_query)
            specific_products = specific_result.scalars().all()
            
            if specific_products:
                print(f"Found {len(specific_products)} matching products:")
                for i, product in enumerate(specific_products, 1):
                    print(f"{i}. Product: {product.线上宝贝名称}")
                    print(f"   Current Brand: '{product.品牌}'")
                    print(f"   Product Code: '{product.货号 or 'None'}'")
                    print("")
            else:
                print("No matching products found")
            
            # Also check other Tods products for comparison
            tods_query = select(ProductMaster).where(
                ProductMaster.线上宝贝名称.like('%Tods女款%')
            ).limit(5)
            
            tods_result = await db.execute(tods_query)
            tods_products = tods_result.scalars().all()
            
            if tods_products:
                print(f"Found {len(tods_products)} other Tods女款 products for comparison:")
                for i, product in enumerate(tods_products, 1):
                    print(f"{i}. Product: {product.线上宝贝名称}")
                    print(f"   Current Brand: '{product.品牌}'")
                    print("")
            
            break
            
    except Exception as e:
        print(f"Error: {e}")
        import traceback
        traceback.print_exc()

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