<?php

namespace App\Services;

use App\Contracts\AuditLogServiceInterface;
use App\Models\AuditLog;
use App\Models\User;
use Illuminate\Support\Facades\Request;

class AuditLogService implements AuditLogServiceInterface
{
    public function log(?User $user, string $action, ?string $description = null): AuditLog
    {
        return AuditLog::create([
            'user_id' => $user?->id,
            'action' => $action,
            'description' => $description,
            'ip_address' => Request::ip(),
            'user_agent' => Request::userAgent(),
        ]);
    }
}
