<?php

namespace App\Http\Controllers\Admin;

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

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

        if ($request->filled('user_id')) $query->where('user_id', $request->user_id);
        if ($request->filled('action')) $query->where('action', 'like', '%' . $request->action . '%');
        if ($request->filled('type')) $query->where('type', $request->type);

        return view('admin.security.audit-logs', [
            'logs' => $query->paginate(20)->withQueryString(),
        ]);
    }
}
