import asyncio
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

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


async def main():
    engine = ProductSearchEngine()
    req = LeadSearchInput(
        inferred=InferredSearch(
            product_line_vn=["Quần lót", "Quần lót tam giác", "Quần lót đùi"],
            gender_by_product="men",
            age_by_product="adult"
        ),
        literal=LiteralSearch(raw_text="sịp nam cực sinh")
    )
    result = await engine.search(req)
    print("Tier:", result.get('tier'))
    print("Mode:", result.get('search_mode'))
    print("Count:", result.get('count'))
    for p in result.get('products', [])[:5]:
        print(p.get('sku'), p.get('name'), p.get('gender'), p.get('product_line'), p.get('_search_source'))

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