"""Shared test fixtures for GodotIQ tests."""

import json
from pathlib import Path

import pytest


@pytest.fixture
def project_root() -> Path:
    """Return the GodotIQ project root directory."""
    return Path(__file__).resolve().parent.parent


@pytest.fixture
def tmp_config(tmp_path: Path) -> Path:
    """Create a temporary .godotiq.json for config loader tests."""
    config = {
        "project": {
            "name": "Test Project",
            "engine": "godot_4",
            "type": "3d",
        },
        "conventions": {"naming": "snake_case"},
        "asset_origins": {},
        "rooms": {},
        "protected_files": ["project.godot"],
        "custom_rules": [],
        "token_optimization": {
            "default_detail": "compact",
            "enable_diff_cache": False,
            "compact_output": True,
            "max_nodes_per_response": 25,
        },
    }
    config_path = tmp_path / ".godotiq.json"
    config_path.write_text(json.dumps(config))
    return config_path


@pytest.fixture
def sample_project_root() -> Path:
    """Return path to the minimal sample Godot project fixture."""
    return Path(__file__).resolve().parent / "fixtures" / "sample_project"


@pytest.fixture(scope="module")
def sample_project_index():
    """Scan the sample project and return a cached ProjectIndex.

    Requires section-05 (project_index.py) to be implemented.
    """
    from godotiq.parsers.project_index import scan_project
    root = Path(__file__).resolve().parent / "fixtures" / "sample_project"
    return scan_project(root)
