<?php
namespace App\Support;
use App\Models\AuditLog;
class AdminAudit
{
    public static function log(string $module, string $action, ?string $referenceNo = null, $old = null, $new = null): void
    {
        if (!session()->has('admin_id')) return;
        AuditLog::create([
            'admin_id' => session('admin_id'),
            'branch_id' => session('admin_branch_id'),
            'module' => $module,
            'action' => $action,
            'reference_no' => $referenceNo,
            'old_values' => $old,
            'new_values' => $new,
            'ip_address' => request()?->ip(),
            'user_agent' => substr((string) request()?->userAgent(), 0, 255),
        ]);
    }
}
