# retoor <retoor@molodetz.nl>

from __future__ import annotations

from ..actions.spec import Action, Param


def arg(
    name: str, description: str, required: bool = False, kind: str = "string"
) -> Param:
    return Param(
        name=name,
        location="body",
        description=description,
        required=required,
        type=kind,
    )


VIRTUAL_TOOL_ACTIONS: tuple[Action, ...] = (
    Action(
        name="tool_create",
        method="LOCAL",
        path="",
        summary="Create a new user-defined tool that runs a stored prompt when called",
        description=(
            "Use when the user asks you to remember a new capability ('when I say X, do Y'). The new "
            "tool becomes callable on the next turn; when called it re-runs you on its stored prompt "
            "plus the user's input. Give a clear trigger-oriented description so you know when to use it."
        ),
        handler="virtual_tool",
        requires_auth=False,
        params=(
            arg(
                "name",
                "Tool name: a letter then letters, digits, or underscores (2-41 chars).",
                required=True,
            ),
            arg(
                "description",
                "When to use the tool and what it does (your trigger hint).",
                required=True,
            ),
            arg(
                "prompt",
                "The instruction the tool runs each time it is called.",
                required=True,
            ),
            arg(
                "input_description",
                "What the single free-form 'input' argument should contain.",
            ),
        ),
    ),
    Action(
        name="tool_list",
        method="LOCAL",
        path="",
        summary="List the user's defined tools with their descriptions and status",
        handler="virtual_tool",
        requires_auth=False,
    ),
    Action(
        name="tool_get",
        method="LOCAL",
        path="",
        summary="Read a user-defined tool's full prompt and settings",
        handler="virtual_tool",
        requires_auth=False,
        params=(arg("name", "Tool name to read.", required=True),),
    ),
    Action(
        name="tool_update",
        method="LOCAL",
        path="",
        summary="Update a user-defined tool's description, prompt, input hint, or enabled state",
        handler="virtual_tool",
        requires_auth=False,
        params=(
            arg("name", "Tool name to update.", required=True),
            arg("description", "New description (optional)."),
            arg("prompt", "New stored prompt (optional)."),
            arg("input_description", "New input hint (optional)."),
            arg(
                "enabled",
                "Enable (true) or disable (false) the tool without deleting it.",
                kind="boolean",
            ),
        ),
    ),
    Action(
        name="tool_delete",
        method="LOCAL",
        path="",
        summary="Delete a user-defined tool",
        handler="virtual_tool",
        requires_auth=False,
        params=(arg("name", "Tool name to delete.", required=True),),
    ),
)
