#!/usr/bin/env python3
"""
Subprocess wrapper for Toolzu operations to avoid asyncio event loop conflicts.
This runs Toolzu 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_toolzu_downloader(config, unified_db):
    """Factory function to create a Toolzu downloader instance."""
    from modules.toolzu_module import ToolzuDownloader

    return ToolzuDownloader(
        headless=config.get('headless', False),
        show_progress=True,
        use_database=True,
        log_callback=None,  # Module uses universal logger
        unified_db=unified_db,
        cookie_file=config.get('cookie_file', '/opt/media-downloader/cookies/toolzu_cookies.json'),
        toolzu_email=config.get('toolzu_email'),
        toolzu_password=config.get('toolzu_password')
    )


# Create the download function using the factory
run_toolzu_download = create_download_wrapper("Toolzu", "toolzu", create_toolzu_downloader)


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