<?php

namespace QUI\InfoPopup\MCP\Popup;

use Mcp\Schema\Result\CallToolResult;
use Mcp\Server\Builder;
use QUI\AI\MCP\ToolHelper;
use QUI\InfoPopup\MCP\AbstractTool;
use Throwable;

class GetPopup extends AbstractTool
{
    public function register(Builder $serverBuilder): void
    {
        $serverBuilder->addTool(
            function (string $project, int $id): CallToolResult | array {
                try {
                    self::checkPermission();

                    return self::getPopupService()->get($project, $id);
                } catch (Throwable $Exception) {
                    return ToolHelper::parseExceptionToResult($Exception);
                }
            },
            name: 'quiqqer_info_popups_get',
            description: 'Returns the complete editable configuration of one project-bound info popup. '
                . 'Use before updating or deleting it.',
            inputSchema: [
                'type' => 'object',
                'additionalProperties' => false,
                'required' => ['project', 'id'],
                'properties' => [
                    'project' => ['type' => 'string', 'description' => 'Project name.'],
                    'id' => ['type' => 'integer', 'description' => 'Info popup ID.', 'minimum' => 1]
                ]
            ]
        );
    }
}
