"""
Pytest configuration and shared fixtures.
"""

import pytest
import tempfile
import shutil
from pathlib import Path
from tools.ingest.base import DesignToken, TokenCollection, TokenType


@pytest.fixture
def temp_dir():
    """Create a temporary directory for tests."""
    temp_path = tempfile.mkdtemp()
    yield Path(temp_path)
    shutil.rmtree(temp_path, ignore_errors=True)


@pytest.fixture
def sample_css():
    """Sample CSS custom properties."""
    return """
    :root {
        --color-primary: #3B82F6;
        --color-secondary: #10B981;
        --spacing-sm: 8px;
        --spacing-md: 16px;
        --spacing-lg: 24px;
        --font-size-base: 16px;
    }
    """


@pytest.fixture
def sample_scss():
    """Sample SCSS variables."""
    return """
    $primary-color: #3B82F6;
    $secondary-color: #10B981;
    $font-family-sans: 'Inter', sans-serif;
    $font-size-base: 16px;
    $spacing-md: 16px;
    """


@pytest.fixture
def sample_json_tokens():
    """Sample JSON design tokens (W3C format)."""
    return {
        "color": {
            "primary": {
                "500": {"value": "#3B82F6", "type": "color"},
                "600": {"value": "#2563EB", "type": "color"}
            },
            "secondary": {
                "500": {"value": "#10B981", "type": "color"}
            }
        },
        "spacing": {
            "sm": {"value": "8px", "type": "dimension"},
            "md": {"value": "16px", "type": "dimension"},
            "lg": {"value": "24px", "type": "dimension"}
        }
    }


@pytest.fixture
def sample_token_collection():
    """Create a sample token collection."""
    tokens = [
        DesignToken(name="color.primary", value="#3B82F6", type=TokenType.COLOR),
        DesignToken(name="color.secondary", value="#10B981", type=TokenType.COLOR),
        DesignToken(name="spacing.md", value="16px", type=TokenType.SPACING),
    ]
    return TokenCollection(tokens=tokens, name="Sample Collection")


@pytest.fixture
def tailwind_config_path(temp_dir):
    """Create a temporary Tailwind config file."""
    config_content = """
module.exports = {
  theme: {
    colors: {
      blue: '#0000FF',
      red: '#FF0000'
    },
    spacing: {
      '1': '4px',
      '2': '8px'
    }
  }
}
"""
    config_file = temp_dir / "tailwind.config.js"
    config_file.write_text(config_content)
    return config_file
