"""audit_record.py — engine-memory AuditRecord writer skeleton.

Substrate for future structured AuditRecord JSON writers. The subrepo
cannot import from the parent's recoil.lib package (own git history;
may be cloned standalone), so the version constant is mirrored locally —
keep it lockstep with recoil/lib/schema_versions.py::AUDIT_RECORD_SCHEMA_VERSION
when bumping.
"""

from __future__ import annotations

from dataclasses import asdict, dataclass, field
from datetime import datetime, timezone
from typing import Any

AUDIT_RECORD_SCHEMA_VERSION: int = 1


@dataclass
class AuditRecord:
    """One audit-log entry written by the engine-memory subrepo.

    Persisted shape: every record carries `schema_version` so future
    readers can branch on shape changes. Adding fields is forward-
    compatible; bump the version constant only when a load-bearing
    field is renamed/removed/retyped.
    """

    record_id: str
    record_type: str
    payload: dict[str, Any] = field(default_factory=dict)
    created_at: str = field(
        default_factory=lambda: datetime.now(timezone.utc)
        .isoformat()
        .replace("+00:00", "Z")
    )
    schema_version: int = AUDIT_RECORD_SCHEMA_VERSION

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)


__all__ = ["AUDIT_RECORD_SCHEMA_VERSION", "AuditRecord"]
