<?php

declare(strict_types=1);

namespace App\Http\Middleware;

// use Hyperf\HttpServer\Contract\ResponseInterface;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;



class InertiaMiddleware implements MiddlewareInterface
{
    public function process($request, RequestHandlerInterface $handler): ResponseInterface
    {
        $response = $handler->handle($request);

        if ($request->hasHeader('X-Inertia')) {
            return $response
                ->withHeader('Content-Type', 'application/json')
                ->withHeader('X-Inertia', 'true');
        }

        return $response;
    }
}
