<?php

namespace App\Http\Controllers\Twilio;

use App\Actions\Communications\GenerateVoiceTokenAction;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class VoiceTokenController
{
    public function __invoke(Request $request, GenerateVoiceTokenAction $action): JsonResponse
    {
        abort_unless($request->user(), 403);

        return response()->json(
            $action->handle($request->user())
        );
    }
}