<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class LogExternalServiceRequests
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        // Log the incoming request
        Log::info('External Service Request', [
            'method' => $request->method(),
            'uri' => $request->fullUrl(),
            'headers' => $request->headers->all(),
            'payload' => $request->all(), // If it's a POST request
        ]);
        Log::info('Raw Request Content:', ['content' => $request->getContent()]);
        Log::info('Request Headers:', $request->headers->all());
        Log::info('Request Body:', $request->all());
        return $next($request);
    }
}
