<?php
/**
 * Pure MCP protocol primitives — no WordPress dependency.
 *
 * @package Ppok\AIToolkit\Lib
 * @license Proprietary — see LICENSE-PROPRIETARY.txt
 *
 * Copyright (c) Ppok. All rights reserved.
 *
 * THIS FILE IS PROPRIETARY. It contains no WordPress symbols, hooks, or
 * derivative work of WordPress core, and is therefore NOT distributed under
 * GPL. Use is governed by LICENSE-PROPRIETARY.txt at the plugin root.
 *
 * Do not add `use` statements, function calls, or class references that depend
 * on WordPress (e.g. WP_*, get_option, wp_*). If you need WP integration,
 * place it in includes/mcp/ or includes/rest/ — those files are GPL.
 */

namespace Ppok\AIToolkit\Lib;

final class Protocol {

	public const VERSION = '2024-11-05';

	public static function encode_envelope( string $method, array $params = array(), $id = null ): array {
		return array(
			'jsonrpc' => '2.0',
			'method'  => $method,
			'params'  => $params,
			'id'      => $id,
		);
	}

	public static function decode_envelope( string $json ): ?array {
		$decoded = json_decode( $json, true );
		if ( ! is_array( $decoded ) || ( $decoded['jsonrpc'] ?? null ) !== '2.0' ) {
			return null;
		}
		return $decoded;
	}
}
