"""RemoteEdge — what an agent in its OWN container can see of the core: the wire, only.

The owner's ruling gives agents *clearly limited access*, and this class is that limit
made structural: a remote agent holds no edge object, no book file, no key — it holds an
MCP client, so it can read exactly what the wire hands over. Whatever `edge_records`
withholds (figures, line contents, internal ERP references), a remote agent cannot read
**even if its code tries** — the container boundary and the withheld discipline are the
same fence seen from two sides.

It quacks just enough of `NEOedge` for the read-only agents: `member_id`, `book.height`,
`sealed`, `records()`. Nothing that writes exists here to be quacked.
"""

from __future__ import annotations

from dataclasses import dataclass


@dataclass(frozen=True)
class _RemoteBook:
    height: int


class RemoteEdge:
    """The agent container's view of one core, over MCP."""

    def __init__(self, client) -> None:
        self._client = client
        status, is_error = client.call("edge_status")
        if is_error:
            raise ConnectionError(f"the core refused edge_status: {status}")
        self.member_id = status["member_id"]
        self.book = _RemoteBook(height=status["book_height"])
        self.sealed = list(status["sealed_periods"])

    def records(self, relation=None) -> list[dict]:
        arguments = {}
        if relation is not None:
            arguments["relation_ref"] = getattr(relation, "ref", relation)
        records, is_error = self._client.call("edge_records", arguments)
        if is_error:
            raise ConnectionError(f"the core refused edge_records: {records}")
        return records
