<?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 DeletePopup extends AbstractTool
{
    public function register(Builder $serverBuilder): void
    {
        $serverBuilder->addTool(
            function (string $project, int $id): CallToolResult | array {
                try {
                    self::checkPermission();

                    return self::getPopupService()->delete($project, $id);
                } catch (Throwable $Exception) {
                    return ToolHelper::parseExceptionToResult($Exception);
                }
            },
            name: 'quiqqer_info_popups_delete',
            description: 'Permanently deletes one project-bound info popup. '
                . 'Use only when deletion was explicitly requested.',
            inputSchema: [
                'type' => 'object',
                'additionalProperties' => false,
                'required' => ['project', 'id'],
                'properties' => [
                    'project' => ['type' => 'string', 'description' => 'Project name.'],
                    'id' => ['type' => 'integer', 'description' => 'Info popup ID.', 'minimum' => 1]
                ]
            ]
        );
    }
}
