<?php

namespace App\Http\Controllers\Twilio;

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

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

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