#!/usr/bin/env python3
from pathlib import Path
import sys

APP_ROOT = Path(__file__).resolve().parents[2]
if str(APP_ROOT) not in sys.path:
    sys.path.insert(0, str(APP_ROOT))

from tool_runtime_helpers import get_current_bot_channel_config
from tool_server_lite.tools.file_tools import BaseTool


class CheapClawGetCurrentBotChannelConfigTool(BaseTool):
    name = "cheapclaw_get_current_bot_channel_config"

    def execute(self, task_id, parameters):
        payload = get_current_bot_channel_config(
            channel=str(parameters.get("channel") or "").strip(),
            include_disabled=bool(parameters.get("include_disabled", False)),
            include_secrets=bool(parameters.get("include_secrets", True)),
        )
        current_channel = str(payload.get("current_channel") or "").strip() or "-"
        return {
            **payload,
            "output": f"current_channel={current_channel} channels={len(payload.get('channels') or [])}",
        }
