#!/usr/bin/env python3
"""
Subprocess wrapper for Snapchat operations to avoid asyncio event loop conflicts.
This runs Snapchat operations in a completely isolated subprocess.

Refactored to use the common wrapper factory from base_subprocess_wrapper.
"""

import sys
from pathlib import Path

# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))

from wrappers.base_subprocess_wrapper import create_download_wrapper, run_wrapper_main


def create_snapchat_downloader(config, unified_db):
    """Factory function to create a Snapchat downloader instance."""
    from modules.snapchat_scraper import SnapchatDirectScraper

    return SnapchatDirectScraper(
        headless=config.get('headless', False),  # Headed mode with Xvfb
        show_progress=True,
        use_database=True,
        log_callback=None,  # Module uses universal logger
        unified_db=unified_db
    )


# Create the download function using the factory
run_snapchat_download = create_download_wrapper("Snapchat", "snapchat", create_snapchat_downloader)


if __name__ == '__main__':
    run_wrapper_main(run_snapchat_download)
