"""Audit logging helper.""" from __future__ import annotations from typing import Any from sqlalchemy.ext.asyncio import AsyncSession from app.models.audit import AuditLog from app.models.user import User async def record_audit( db: AsyncSession, actor: User | None, action: str, target_type: str | None = None, target_id: int | None = None, detail: dict[str, Any] | None = None, ) -> None: db.add( AuditLog( actor_id=actor.id if actor else None, actor_email=actor.email if actor else None, action=action, target_type=target_type, target_id=target_id, detail=detail, ) ) await db.commit()