<?php

namespace App\Http\Controllers\Webhooks\Communications;

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

class TwilioSmsStatusController extends Controller
{
    public function __invoke(Request $request, IngestProviderEventAction $ingest): JsonResponse
    {
        // Twilio posts form data.  The `mid` query param is added by us when
        // building the statusCallback URL in TwilioSmsProvider.
        $payload = array_merge(
            $request->query(),
            $request->post(),
        );

        $ingest->handleTwilio($payload);

        return response()->json(['status' => 'ok'], 200);
    }
}
