"""Shared test fixtures for CogniGraph."""

import pytest
import networkx as nx

from cognigraph.core.graph import CogniGraph
from cognigraph.core.node import CogniNode
from cognigraph.core.edge import CogniEdge
from cognigraph.core.message import Message
from cognigraph.core.state import NodeState
from cognigraph.core.types import ReasoningType
from cognigraph.backends.mock import MockBackend


@pytest.fixture
def mock_backend():
    """A mock backend that returns configurable responses."""
    return MockBackend(responses=[
        "This is relevant to the query. Based on my knowledge, "
        "the key finding is X. Confidence: 75%",
        "Building on neighbor analysis, I agree with the assessment "
        "but add nuance Y. Confidence: 82%",
        "Synthesizing all inputs: the conclusion is Z with "
        "strong evidence from multiple sources. Confidence: 90%",
    ])


@pytest.fixture
def sample_nx_graph():
    """A small NetworkX graph for testing."""
    G = nx.Graph()
    G.add_node("n1", label="Node A", type="Concept", description="First concept")
    G.add_node("n2", label="Node B", type="Concept", description="Second concept")
    G.add_node("n3", label="Node C", type="Concept", description="Third concept")
    G.add_node("n4", label="Node D", type="Concept", description="Fourth concept")
    G.add_node("n5", label="Node E", type="Concept", description="Fifth concept hub")

    G.add_edge("n1", "n2", relationship="RELATED_TO", weight=0.8)
    G.add_edge("n2", "n3", relationship="RELATED_TO", weight=0.6)
    G.add_edge("n3", "n4", relationship="CONFLICTS_WITH", weight=0.9)
    G.add_edge("n5", "n1", relationship="CONTAINS", weight=0.7)
    G.add_edge("n5", "n2", relationship="CONTAINS", weight=0.7)
    G.add_edge("n5", "n3", relationship="CONTAINS", weight=0.7)
    G.add_edge("n5", "n4", relationship="REFERENCES", weight=0.5)
    return G


@pytest.fixture
def sample_graph(sample_nx_graph):
    """A CogniGraph built from the sample NetworkX graph."""
    return CogniGraph.from_networkx(sample_nx_graph)


@pytest.fixture
def sample_message():
    """A sample message for testing."""
    return Message(
        source_node_id="n1",
        target_node_id="n2",
        round=1,
        content="Analysis shows regulatory conflict. Confidence: 80%",
        reasoning_type=ReasoningType.ASSERTION,
        confidence=0.8,
        evidence=["n1"],
    )
