# at top of persist_snapshot.py:

from typing import Dict
from datetime import datetime
from sqlalchemy import (
    update
)
from models.market import (
    SubcategoryRedirect,
)
from shared.db.session import get_session

# --- Models are unchanged, see original code ---

# ---------------------- Helper fns called from scraper ------------------------


async def save_subcategory_redirects(mapping: Dict[str, str]) -> None:
    async with get_session() as session:
        await _save_subcategory_redirects(session, mapping)
        await session.commit()


async def _save_subcategory_redirects(session, mapping: Dict[str, str]) -> None:
    await session.execute(update(SubcategoryRedirect).where(SubcategoryRedirect.deleted_at.is_(None)).values(deleted_at=datetime.utcnow()))
    for old, new in mapping.items():
        session.add(SubcategoryRedirect(old_path=old, new_path=new))



  #for slug in items:
  #    product_slugs.add(slug)
