<?php

namespace App\Http\Controllers;

use App\Models\SpaceUpdate;
use Illuminate\Http\Request;

class LiveController extends Controller
{
    public function poll(Request $request)
    {
        $user = $request->user();
        $spaceId = (string) ($user?->profile?->default_space_id ?? '');
        abort_unless($spaceId !== '', 403);

        return response()->json([
            'space_id' => $spaceId,
            'version' => SpaceUpdate::currentVersion($spaceId),
            'now' => now()->toISOString(),
        ]);
    }
}

