public function handle(Request $request, Closure $next, MediaTypeGuard $guard = null)
    {
        //
        $guard = $guard ?? app(MediaTypeGuard::class);

        if (!$guard->validateExistingContentType($request) || !$guard->hasCorrectHeadersForData($request)) {
            $errors = (new ErrorCollection())->add(ErrorFactory::buildUnsupportedMediaType());
            $encoder = Encoder::instance([], new EncoderOptions(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

            return new Response($encoder->encodeErrors($errors), 415, ['Content-Type' => $guard->getContentType()]);
        }

        if (!$guard->hasCorrectlySetAcceptHeader($request)) {
            $errors = (new ErrorCollection())->add(ErrorFactory::buildUnacceptable());
            $encoder = Encoder::instance([], new EncoderOptions(JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));

            return new Response($encoder->encodeErrors($errors), 406, ['Content-Type' => $guard->getContentType()]);
        }

        $response = $next($request);
        $response->header('Content-Type', $guard->getContentType());

        return $response;
    }