
from worker.stylist_engine import StylistEngine


def test_engine():
    engine = StylistEngine()
    print("Catalog loaded. Finding adult product...")
    catalog = engine._get_catalog()
    
    # find an adult shirt
    adult_product = None
    for p in catalog:
        gender = p.get('gender', '').lower()
        if gender in ['nam', 'nữ', 'nu', 'women', 'men']:
            adult_product = p
            break
            
    if not adult_product:
        print("No adult product found.")
        return
        
    code = adult_product['code']
    print(f"Testing Code: {code} | Name: {adult_product['name']} | Gender: {adult_product['gender']}")
    
    print("\n--- 1. Testing 'compute_dynamic_rule_matches' (AI MATCHES) ---")
    matches = engine.compute_dynamic_rule_matches(code)
    
    if not matches:
        print("No AI matches found.")
    else:
        for occ, roles in matches.items():
            for role, items in roles.items():
                for item in items[:2]:
                    item_gender = item.get('gender', 'unknown').lower()
                    item_name = item.get('name', 'unknown')
                    if 'bé' in item_name.lower() or 'bé' in item_gender or 'be' in item_gender:
                        print(f"  [AI-MATCH] FOUND KID: {item['code']} - {item_name} (gender: {item_gender})")
                    else:
                        print(f"  [AI-MATCH] OK: {item['code']} - {item_name} (gender: {item_gender})")

    print("\n--- 2. Testing 'compute_super_classifications_sql' (SUPER CLASSIFICATIONS) ---")
    classifications = engine.compute_super_classifications_sql(code)
    if not classifications:
        print("No classification matches found.")
    else:
        for group, groups_dict in classifications.items():
            for key, items in groups_dict.items():
                for item in items[:2]:
                    item_name = item.get('name', 'unknown')
                    if 'bé' in item_name.lower():
                        print(f"  [SUPER-CLASS] FOUND KID: {item['code']} - {item_name}")
                    else:
                        print(f"  [SUPER-CLASS] OK: {item['code']} - {item_name}")

if __name__ == "__main__":
    test_engine()
