<?php
require_once __DIR__ . '/functions.php';

/**
 * CENTRAL AUDIT LOGGER
 * Used by admin, customer, system events
 */
function audit_log(
  mysqli $conn,
  int $actorId,
  string $action,
  array $meta = [],
  ?string $ip = null
): void {

  $json = json_encode($meta, JSON_UNESCAPED_SLASHES);

  $st = $conn->prepare("
    INSERT INTO audit_logs (actor_id, action, meta, ip)
    VALUES (?, ?, ?, ?)
  ");
  $st->bind_param(
    "isss",
    $actorId,
    $action,
    $json,
    $ip
  );
  $st->execute();
}
