"""Shared fixtures for idfkit-mcp tests."""

from __future__ import annotations

import pytest
from idfkit import new_document

from idfkit_mcp.state import ServerState, get_state, reset_sessions


@pytest.fixture(autouse=True)
def _reset_state() -> None:
    """Reset the session registry before each test."""
    reset_sessions()
    state = get_state()
    state.persistence_enabled = False


@pytest.fixture()
def state_with_model() -> ServerState:
    """Return server state with a new empty model loaded."""
    state = get_state()
    doc = new_document()
    state.document = doc
    state.schema = doc.schema
    return state


@pytest.fixture()
def state_with_zones() -> ServerState:
    """Return server state with a model containing zones and surfaces."""
    state = get_state()
    doc = new_document()
    state.document = doc
    state.schema = doc.schema

    doc.add("Zone", "Office")
    doc.add("Zone", "Corridor")
    doc.add(
        "BuildingSurface:Detailed",
        "Office_Wall",
        surface_type="Wall",
        construction_name="",
        zone_name="Office",
        outside_boundary_condition="Outdoors",
        sun_exposure="SunExposed",
        wind_exposure="WindExposed",
        validate=False,
    )
    return state


@pytest.fixture()
def state_with_singletons() -> ServerState:
    """Return server state with a model containing singleton objects.

    ``new_document()`` already creates default singletons (SimulationControl,
    GlobalGeometryRules, etc.), so we just use those.
    """
    state = get_state()
    doc = new_document()
    state.document = doc
    state.schema = doc.schema
    return state
