# tests/integration/middleware/conftest.py
"""
Fixtures specific to middleware integration tests.
"""

import pytest

from models.database.vendor import Vendor
from models.database.vendor_domain import VendorDomain
from models.database.vendor_theme import VendorTheme


@pytest.fixture
def vendor_with_subdomain(db):
    """Create a vendor with subdomain for testing."""
    vendor = Vendor(
        name="Test Vendor", code="testvendor", subdomain="testvendor", is_active=True
    )
    db.add(vendor)
    db.commit()
    db.refresh(vendor)
    return vendor


@pytest.fixture
def vendor_with_custom_domain(db):
    """Create a vendor with custom domain for testing."""
    vendor = Vendor(
        name="Custom Domain Vendor",
        code="customvendor",
        subdomain="customvendor",
        is_active=True,
    )
    db.add(vendor)
    db.commit()
    db.refresh(vendor)

    # Add custom domain
    domain = VendorDomain(
        vendor_id=vendor.id, domain="customdomain.com", is_active=True, is_primary=True
    )
    db.add(domain)
    db.commit()

    return vendor


@pytest.fixture
def vendor_with_theme(db):
    """Create a vendor with custom theme for testing."""
    vendor = Vendor(
        name="Themed Vendor",
        code="themedvendor",
        subdomain="themedvendor",
        is_active=True,
    )
    db.add(vendor)
    db.commit()
    db.refresh(vendor)

    # Add custom theme
    theme = VendorTheme(
        vendor_id=vendor.id,
        primary_color="#FF5733",
        secondary_color="#33FF57",
        logo_url="/static/vendors/themedvendor/logo.png",
        favicon_url="/static/vendors/themedvendor/favicon.ico",
        custom_css="body { background: #FF5733; }",
    )
    db.add(theme)
    db.commit()

    return vendor


@pytest.fixture
def inactive_vendor(db):
    """Create an inactive vendor for testing."""
    vendor = Vendor(
        name="Inactive Vendor", code="inactive", subdomain="inactive", is_active=False
    )
    db.add(vendor)
    db.commit()
    db.refresh(vendor)
    return vendor
