<?php

use App\Models\Audit;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;

function audit_log(
    $event,
    $module,
    $model = null,
    $old = null,
    $new = null
) {
    Audit::create([
        'event' => $event,
        'module' => $module,
        'auditable_type' => $model ? get_class($model) : null,
        'auditable_id' => $model?->id,
        'user_id' => Auth::id(),
        'company_id' => Auth::user()?->company_id,
        'old_values' => $old,
        'new_values' => $new,
        'ip_address' => Request::ip(),
        'user_agent' => Request::userAgent(),
    ]);
}
