#!/usr/bin/env python3
"""
Verify the specific case mentioned by user
"""
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 verify_specific_case():
    """Verify the specific Tods case"""
    print("验证具体的Tods案例...")
    
    try:
        async for db in get_db():
            # Look for the specific product mentioned
            specific_query = select(ProductMaster).where(
                ProductMaster.线上宝贝名称.like('%卡其色麻花拖鞋%')
            )
            
            specific_result = await db.execute(specific_query)
            specific_products = specific_result.scalars().all()
            
            print("查找: 'Tods女款卡其色麻花拖鞋'")
            if specific_products:
                for product in specific_products:
                    print(f"✅ 找到产品:")
                    print(f"   产品名称: {product.线上宝贝名称}")
                    print(f"   品牌: '{product.品牌}' ← 现在应该是 'Tods'")
                    print(f"   货号: '{product.货号}'")
                    print("")
            else:
                print("❌ 没有找到匹配的产品")
            
            # Check other Tods女款 products
            print("检查其他Tods女款产品:")
            tods_query = select(ProductMaster).where(
                ProductMaster.线上宝贝名称.like('%Tods女款%')
            ).limit(5)
            
            tods_result = await db.execute(tods_query)
            tods_products = tods_result.scalars().all()
            
            for i, product in enumerate(tods_products, 1):
                print(f"{i}. {product.线上宝贝名称[:60]}...")
                print(f"   品牌: '{product.品牌}' ← 应该都是 'Tods'")
                print("")
            
            # Summary
            tods_count = await db.scalar(
                select(func.count(ProductMaster.id)).where(ProductMaster.品牌 == 'Tods')
            )
            
            print(f"📊 总结: 数据库中有 {tods_count} 个Tods品牌的产品")
            
            break
            
    except Exception as e:
        print(f"Error: {e}")
        import traceback
        traceback.print_exc()

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