<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\AuditLog;
use App\Models\User;
use Illuminate\Http\Request;

class AuditoriaController extends Controller
{
    public function index(Request $request)
    {
        $query = AuditLog::with('user')->latest();

        if ($request->filled('user_id')) {
            $query->where('user_id', $request->user_id);
        }
        if ($request->filled('acao')) {
            $query->where('acao', 'like', $request->acao . '%');
        }
        if ($request->filled('data')) {
            $query->whereDate('created_at', $request->data);
        }

        $logs   = $query->paginate(50)->withQueryString();
        $users  = User::orderBy('name')->get();

        return view('pages.admin.auditoria', compact('logs', 'users'));
    }
}
