<?php

namespace App\Http\Middleware;

use App\Services\WorkspaceBootstrapService;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureCollabsWorkspace
{
    public function __construct(
        private WorkspaceBootstrapService $bootstrap,
    ) {}

    public function handle(Request $request, Closure $next): Response
    {
        $user = $request->user();
        if ($user !== null) {
            $this->bootstrap->bootstrap($user);
        }

        return $next($request);
    }
}
