<?php
/**
 * Small shape helpers for agent-loop tool calls and tool result messages.
 *
 * @package Niwa_AI
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Niwa_AI_Agent_Tool_Call_Utils {

	public static function result_message( $call_id, $result ) {
		return array(
			'role'         => 'tool',
			'tool_call_id' => $call_id,
			'content'      => wp_json_encode( is_array( $result ) ? $result : array() ),
		);
	}

	public static function decode_args( $call_args ) {
		if ( is_string( $call_args ) ) {
			$decoded_args = json_decode( $call_args, true );

			return is_array( $decoded_args ) ? $decoded_args : array();
		}

		return is_array( $call_args ) ? $call_args : array();
	}

	public static function bridge_call( $call_id, $call_name, $call_args ) {
		return array(
			'id'        => $call_id,
			'name'      => $call_name,
			'arguments' => $call_args,
		);
	}
}
