# tests/fixtures/marketplace_import_job_fixtures.py
"""
Marketplace import job test fixtures.

Note: Fixtures should NOT use db.expunge() as it breaks lazy loading.
See tests/conftest.py for details on fixture best practices.
"""

import pytest

from app.modules.marketplace.models import MarketplaceImportJob


@pytest.fixture
def test_marketplace_import_job(db, test_store, test_user):
    """Create a test marketplace import job."""
    job = MarketplaceImportJob(
        marketplace="amazon",
        status="completed",
        source_url="https://test-marketplace.example.com/import",
        store_id=test_store.id,
        user_id=test_user.id,
        imported_count=5,
        updated_count=3,
        total_processed=8,
        error_count=0,
        error_message=None,
    )
    db.add(job)
    db.commit()
    db.refresh(job)
    return job


def create_test_marketplace_import_job(db, store_id, user_id, **kwargs):
    """Helper function to create MarketplaceImportJob with defaults."""
    defaults = {
        "marketplace": "test",
        "status": "pending",
        "source_url": "https://test.example.com/import",
        "store_id": store_id,
        "user_id": user_id,
        "imported_count": 0,
        "updated_count": 0,
        "total_processed": 0,
        "error_count": 0,
        "error_message": None,
    }
    defaults.update(kwargs)

    job = MarketplaceImportJob(**defaults)
    db.add(job)
    db.commit()
    db.refresh(job)
    return job
