"""Bitbucket tool configuration."""

from __future__ import annotations

from typing import TYPE_CHECKING

from mindroom.tool_system.declarations import ConfigField, SetupType, ToolCategory, ToolStatus
from mindroom.tool_system.registration import register_tool_with_metadata

if TYPE_CHECKING:
    from agno.tools.bitbucket import BitbucketTools


@register_tool_with_metadata(
    name="bitbucket",
    display_name="Bitbucket",
    description="Manage Bitbucket repositories, pull requests, commits, and issues",
    category=ToolCategory.DEVELOPMENT,
    status=ToolStatus.REQUIRES_CONFIG,
    setup_type=SetupType.SPECIAL,
    icon="SiBitbucket",
    icon_color="text-blue-600",
    config_fields=[
        ConfigField(
            name="username",
            label="Username",
            type="text",
            required=True,
            placeholder="Bitbucket username",
            description="Bitbucket username",
        ),
        ConfigField(
            name="password",
            label="App Password",
            type="password",
            required=False,
            description="App password. Use either this or token.",
        ),
        ConfigField(
            name="token",
            label="Token",
            type="password",
            required=False,
            description="Access token. Use either this or password.",
        ),
        ConfigField(
            name="workspace",
            label="Workspace",
            type="text",
            required=True,
            placeholder="my-workspace",
        ),
        ConfigField(
            name="repo_slug",
            label="Repository Slug",
            type="text",
            required=True,
            placeholder="my-repo",
        ),
        ConfigField(
            name="server_url",
            label="Server URL",
            type="url",
            required=False,
            default="api.bitbucket.org",
        ),
        ConfigField(
            name="api_version",
            label="API Version",
            type="text",
            required=False,
            default="2.0",
        ),
    ],
    dependencies=["requests"],
    docs_url="https://docs.agno.com/tools/toolkits/others/bitbucket",
    helper_text="Create an app password at [Bitbucket Settings](https://bitbucket.org/account/settings/app-passwords/)",
    function_names=(
        "create_repository",
        "get_pull_request_changes",
        "get_pull_request_details",
        "get_repository_details",
        "list_all_pull_requests",
        "list_issues",
        "list_repositories",
        "list_repository_commits",
    ),
)
def bitbucket_tools() -> type[BitbucketTools]:
    """Return Bitbucket tools for repository management."""
    from agno.tools.bitbucket import BitbucketTools

    return BitbucketTools
