<?php

declare( strict_types=1 );

namespace Limb_Chatbot\Includes\Services\System_Message\Chunks;

use Limb_Chatbot\Includes\Data_Objects\Action;
use Limb_Chatbot\Includes\Utilities\Chatbot_Utility;


/**
 * Actions Chunk
 *
 * Describes available actions and when to use them.
 *
 * @since 1.1.1
 */
class Actions_Chunk extends System_Message_Chunk {

	private array $actions;

	public function __construct( Chatbot_Utility $utility ) {
		$this->actions = $utility->get_actions()->get();
	}

	public function get_title(): string {
		return 'Available Actions';
	}

	public function get_content(): array {
		$lines = [
			"Actions can be triggered only when explicitly requested by the user.",
			"If the user asks to repeat an action, execute the same tool call AT ONCE again without hallucinating, or asking anything yourself.",
			"Suggest them when appropriate.",
		];

		foreach ( $this->actions as $action ) {
			if ( $action instanceof Action ) {
				$lines[] = "- {$action->get_name()}: {$action->get_ai_instructions()}";
			}
		}

		return $lines;
	}

	public function get_priority(): int {
		return 80;
	}

	public function should_include(): bool {
		return ! empty( $this->actions );
	}
}

