<?php

namespace Licenzo\Http\Middleware;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

use Licenzo\Framework\Http\Request;
use Licenzo\Framework\Http\Response;

class ValidateRequest
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, \Closure $next)
    {
        // Basic request validation
        if (!$this->isValidRequest($request)) {
            return new Response([
                'success' => false,
                'message' => 'Invalid request format'
            ], 400);
        }

        return $next($request);
    }

    /**
     * Check if the request is valid.
     */
    protected function isValidRequest(Request $request): bool
    {
        return in_array(
            $request->getMethod(),
            ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS']
        );
    }
}
