import asyncio
import logging

from agent.lead_stage_agent.product_search_engine import (InferredSearch, LeadSearchInput, LiteralSearch,
                                                          ProductSearchEngine)

logging.basicConfig(level=logging.INFO)

async def main():
    engine = ProductSearchEngine()
    
    # Test case 1: Áo 30/4 màu đỏ -> AI nên điền raw_text cho literal và filter màu đỏ cho inferred
    req = LeadSearchInput(
        literal=LiteralSearch(raw_text="áo 30/4 màu đỏ"),
        inferred=InferredSearch(
            product_line_vn=["Áo phông"], 
            keywords=["cờ đỏ sao vàng"],
            master_color="đỏ"
        ),
        reasoning="User tim áo 30/4 màu đỏ."
    )
    
    res = await engine.search(req)
    
    print("\n" + "="*50)
    print(f"SEARCH MODE: {res.get('search_mode')}")
    print(f"LITERAL TEXT: {res.get('literal_text')}")
    print(f"COUNT: {res.get('count')}")
    print(f"FALLBACK MSG: {res.get('fallback_message')}")
    print("="*50)
    
    for i, p in enumerate(res.get('products', [])[:5]):
        print(f"[{i+1}] {p.get('product_name')} | SKU: {p.get('magento_ref_code')} | Source: {p.get('_search_source')}")

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