import os
import sys
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# 設定路徑
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, BASE_DIR)

from database.models import Product

# 資料庫路徑
DB_PATH = os.path.join(BASE_DIR, 'data', 'momo_database.db')
engine = create_engine(f'sqlite:///{DB_PATH}')
Session = sessionmaker(bind=engine)
session = Session()

# 指定的商品編號
i_codes = ['14672839', '9216349', '13261678', '6676895', '13240823', '13240822', '10911080', '3876337', '8863611']

print("🔍 檢查指定商品的圖片 URL:\n")
print("=" * 100)

for i_code in i_codes:
    product = session.query(Product).filter(Product.i_code == i_code).first()
    if product:
        print(f"\n[{i_code}] {product.name[:60]}...")
        print(f"  當前圖片: {product.image_url}")
        
        # 檢查 URL 是否包含 i_code
        if product.image_url and i_code in product.image_url:
            print(f"  ✅ URL 包含商品編號")
        elif product.image_url:
            print(f"  ❌ URL 不包含商品編號")
        else:
            print(f"  ⚠️  無圖片")
    else:
        print(f"\n[{i_code}] ⚠️ 找不到此商品")

print("\n" + "=" * 100)
session.close()
