"""Pytest configuration and fixtures."""

import tempfile
from collections.abc import Iterator
from pathlib import Path

import pytest


@pytest.fixture
def temp_dir() -> Iterator[Path]:
    """Create a temporary directory for tests."""
    with tempfile.TemporaryDirectory() as tmpdir:
        yield Path(tmpdir)


@pytest.fixture(autouse=True)
def isolate_license_file(temp_dir: Path, monkeypatch) -> None:
    """Isolate license file for each test."""
    license_file = temp_dir / "license.json"
    monkeypatch.setattr(
        "apiposture_pro.licensing.manager.ProLicenseManager.LICENSE_FILE", license_file
    )


@pytest.fixture(autouse=True)
def isolate_extension_dir(temp_dir: Path, monkeypatch) -> None:
    """Isolate extension directory for each test."""
    ext_dir = temp_dir / "extensions" / "ApiPosturePro"
    monkeypatch.setattr(
        "apiposture_pro.deployment.deployer.ExtensionDeployer.EXTENSION_DIR", ext_dir
    )
