# backend/app/security/audit.py — 보안 감사 로그 기록 (approval_log 와 구분)
import uuid

from sqlmodel import Session

from ..models import AuditLog


def audit(
    session: Session,
    user_id: str | None,
    action: str,
    *,
    target: str | None = None,
    ip: str | None = None,
    detail: str | None = None,
) -> None:
    session.add(
        AuditLog(
            id="al-" + uuid.uuid4().hex[:10],
            user_id=user_id,
            action=action,
            target=target,
            ip=ip,
            detail=detail,
        )
    )
    session.commit()
