"""Transport-neutral cassette interaction model."""

import base64
from dataclasses import dataclass


@dataclass(frozen=True)
class RecordedInteraction:
    """One completed HTTP exchange with exact response chunks."""

    method: str
    url: str
    status: int
    request_body: bytes
    response_chunks: tuple[bytes, ...]

    def as_dict(self) -> dict[str, object]:
        """Encode byte fields losslessly for JSON storage."""
        return {
            "method": self.method,
            "url": self.url,
            "status": self.status,
            "request_body_base64": _encode(self.request_body),
            "response_body_base64": _encode(b"".join(self.response_chunks)),
            "response_chunks_base64": [_encode(chunk) for chunk in self.response_chunks],
        }


def _encode(value: bytes) -> str:
    return base64.b64encode(value).decode("ascii")
