"""Patch TAG_TO_BITMAP_COL với giá trị thực tế từ DB."""
import re

path = r'D:\cnf\chatbot-canifa-feedback\backend\agent\tag_search_agent_v2\tag_search_tool.py'

with open(path, encoding='utf-8') as f:
    content = f.read()

# Find and replace the TAG_TO_BITMAP_COL block using regex
pattern = r'(TAG_TO_BITMAP_COL: dict\[str, tuple\[str, str\]\] = \{)[^}]+(})'
replacement = r'''TAG_TO_BITMAP_COL: dict[str, tuple[str, str]] = {
    # Trục 3 — style (cột `style` có BITMAP index)
    # DB values: Street, Basic Update, Feminine, Basic, Athleisure, Cute, Essential, Smart Casual, Utility, Trend, Dynamic, Preppy
    "style:thanh_lich":  ("style", "Feminine"),
    "style:nang_dong":   ("style", "Dynamic"),
    "style:basic":       ("style", "Basic"),
    "style:ca_tinh":     ("style", "Street"),
    "style:de_thuong":   ("style", "Cute"),
    "style:tre_trung":   ("style", "Trend"),
    "style:toi_gian":    ("style", "Essential"),
    "style:smart_casual":("style", "Smart Casual"),
    # Trục 4 — fitting (cột `fitting` có BITMAP index)
    # DB values: Boxy, Skinny, Oversize, Relax, Slimfit, Regular, Slim
    "fit:oversize":  ("fitting", "Oversize"),
    "fit:slim":      ("fitting", "Slim"),
    "fit:regular":   ("fitting", "Regular"),
    "fit:wide_leg":  ("fitting", "Relax"),
    "fit:cropped":   ("fitting", "Boxy"),
    "fit:relaxed":   ("fitting", "Relax"),
    # Trục 2a — season_sale (cột `season_sale` có BITMAP index)
    # DB values thực tế: Year, Winter, Summer
    "wthr:mua_he":   ("season_sale", "Summer"),
    "wthr:mua_dong": ("season_sale", "Winter"),
}'''

new_content, n = re.subn(pattern, replacement, content, flags=re.DOTALL)
if n > 0:
    with open(path, 'w', encoding='utf-8') as f:
        f.write(new_content)
    print(f'✅ Patched {n} occurrence(s)')
else:
    print('❌ Pattern not found — printing lines 360-385:')
    for i, line in enumerate(content.splitlines()[359:385], 360):
        print(f'{i}: {line}')
