<?php

declare(strict_types=1);

namespace App\Middlewares;

use App\Helpers\Request;
use App\Models\User;

class EventMiddleware
{
    public function handle(Request $request): mixed
    {
        $userId = $request->param('auth_user_id');

        if (!$userId) {
            return 'Usuario no autenticado';
        }

        $userModel = new User();
        $user = $userModel->findById((int) $userId);

        if (!$user) {
            return 'Usuario no encontrado';
        }

        $request->setRouteParams([
            'auth_user_event_id' => $user['current_event_id'] ? (int) $user['current_event_id'] : 0,
        ]);

        return null;
    }
}
