#!/usr/bin/env python3
"""
Test specific brand extraction issues
"""
import sys
sys.path.append('backend')

from app.utils.text_parser import BrandExtractor

def test_specific_brands():
    """Test specific brand extraction cases"""
    extractor = BrandExtractor()
    
    test_cases = [
        {
            "name": "小王国S MaxMara女款深灰色羊毛双排扣短大衣 CAPE 002代购8.18",
            "expected": "S MaxMara",
            "description": "Should extract S MaxMara as independent brand"
        },
        {
            "name": "小王国 Tods 黑色小Logo双肩包 XBMMDDG0300GECB999 8.14",
            "expected": "Tods",
            "description": "Should extract Tods only, not including description"
        },
        {
            "name": "小王国 Tods 蓝色条纹长袖衬衫 X6WA149618EWRK0492 8.15 LA",
            "expected": "Tods",
            "description": "Should extract Tods only, not including description"
        },
        {
            "name": "Tods女款牛仔拼色镂空锁扣装饰踩鞋XXW00G0GW40R43ZZEU代购8.15LA",
            "expected": "Tods",
            "description": "Should extract Tods only, not including description"
        },
        {
            "name": "小王国S MaxMara粉色短款纯羊毛大衣MOON 061代购8.18",
            "expected": "S MaxMara",
            "description": "Should extract S MaxMara as independent brand"
        },
        {
            "name": "小王国SportMax女款黑色羊皮皮衣GEL 003 代购8.18",
            "expected": "SportMax",
            "description": "Should extract SportMax only, not including description"
        },
        {
            "name": "小王国SportMax女款卡其色腰带款风衣RICAMO 001代购8.18",
            "expected": "SportMax",
            "description": "Should extract SportMax only, not including description"
        }
    ]
    
    print("Testing Specific Brand Extraction Issues")
    print("=" * 50)
    
    passed = 0
    total = len(test_cases)
    
    for i, case in enumerate(test_cases, 1):
        result = extractor.extract_brand(case["name"])
        expected = case["expected"]
        
        print(f"\nTest {i}: {case['description']}")
        print(f"Input: {case['name']}")
        print(f"Expected: {expected}")
        print(f"Got: {result}")
        
        # Debug: show candidates
        candidates = extractor._extract_brand_candidates(case["name"])
        print(f"Candidates: {candidates}")
        
        if result == expected:
            print("✅ PASS")
            passed += 1
        else:
            print("❌ FAIL")
    
    print(f"\n{'='*50}")
    print(f"Results: {passed}/{total} tests passed ({passed/total*100:.1f}%)")
    
    return passed == total

if __name__ == "__main__":
    success = test_specific_brands()
    sys.exit(0 if success else 1)