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 = ['6323590', '7904362', '5954422', '6009343', '4248163', '3331634', '7351198', 
           '12589232', '11118441', '10755887', '9009264', '9562474', '11038732', '10901361', 
           '9250857', '5477268', '9600967', '10440331', '10080994', '9900915', '3821684', 
           '10567236', '13351736', '13351734', '12777975', '11640264', '5894654', '10050962', 
           '8318051', '11593427', '9857434']

correct = 0
incorrect = 0

for i_code in i_codes:
    product = session.query(Product).filter(Product.i_code == i_code).first()
    if product and product.image_url and i_code in product.image_url:
        correct += 1
    else:
        incorrect += 1
        if product:
            print(f"❌ [{i_code}] {product.image_url}")

print(f"\n📊 驗證結果: ✅ {correct}/{len(i_codes)} 正確")
if incorrect > 0:
    print(f"❌ {incorrect} 個錯誤")

session.close()
