[{'Text': '    def gbs_get_status(\n        country: str = "",\n        operator: str = "",\n        period: str = "",\n        ctx=None,\n    ) -> str:\n        """GBS status at any zoom level: country overview → operator detail → period drill-down.\n\n        GBS (Global Broadband Statistics) is a quarterly reporting process.\n        Use this tool to understand what data exists, what\'s missing, and\n        what needs to be entered for any operator/period combination.\n\n        Zoom levels:\n          country only       → coverage overview: how many operators have data,\n                               which ones are complete, which are missing entirely\n          + operator         → that operator\'s records and gaps for the current period\n          + period           → specific quarter (YYYYQN format, e.g. "2025Q3")\n                               defaults to current period from GlobalVariables\n\n        Args:\n            country:  Country name (exact match, e.g. "United Kingdom")\n            operator: Operator name (exact match, case-sensitive).\n                      Leave empty for country-level overview.\n            period:   Quarter string (e.g. "2025Q3", "2024Q4").\n                      Leave empty to use the current period.\n\n        Returns:\n            Formatted status report. For country level: total operators,\n            coverage split, lists of who has data and who doesn\'t.\n            For operator level: records table, gap analysis, state breakdown, admin URL.\n        """\n        if not country:\n            return "Error: country is required (e.g. \'United Kingdom\'). Use gbs_list_countries() to discover available countries."\n\n        op_arg = operator.strip() if operator else None\n        period_arg = period.strip() if period else None\n\n        data = _run_status_query(country, op_arg, period_arg)\n        if data.get("error"):\n            return f"Query failed: {data[\'error\']}"\n\n        cp = data.get("currentPeriod", "?")\n        tp = data.get("targetPeriod", cp)\n        docs = data.get("docs", [])\n\n        if op_arg:\n            # ── Operator level ──\n            if not docs:\n                return (\n                    f"Operator \'{operator}\' not found in \'{country}\'.\\n"\n                    f"Check exact spelling (case-sensitive). "\n                    f"Use gbs_get_status(country=\'{country}\') to see all operators."\n                )\n            return _format_operator_status(docs[0], tp, country)\n\n        # ── Country level ──\n        return _format_country_status(docs, cp, country)\n\n    def _format_country_status(docs: list, period: str, country: str) -> str:\n        """Format country-level roll-up."""\n        with_data = [d for d in docs if d.get("statCount", 0) > 0]\n        without = [d for d in docs if d.get("statCount", 0) == 0]\n        total = len(docs)\n\n        lines = [\n            f"GBS STATUS: {country} — period {period}",\n            f"Operators: {total} total | {len(with_data)} with data | {len(without)} without data",\n        ]\n        if total > 0:\n            lines.append(f"Coverage: {round(100 * len(with_data) / total, 1)}%")\n        lines.append("")\n\n        if with_data:\n            lines.append("OPERATORS WITH DATA (by record count):")\n            for d in sorted(with_data, key=lambda x: -x["statCount"])[:50]:\n                record_label = "record" if d["statCount"] == 1 else "records"\n                lines.append(f"  {d[\'name\'][:40]:40s} {d[\'statCount\']} {record_label}")\n            lines.append("")\n\n        if without:\n            shown = without[:30]\n            lines.append(f"OPERATORS WITHOUT DATA ({len(shown)} of {len(without)} shown):")\n            lines.append(f"  {\', \'.join(d[\'name\'] for d in shown)}")\n            if len(without) > 30:\n                lines.append(f"  ... and {len(without) - 30} more")\n            lines.append("")\n\n        lines.append(f"Admin: {ADMIN_BASE}/admin")\n        return "\\n".join(lines)\n\n    def _format_operator_status(doc: dict, period: str, country: str) -> str:\n        """Format single-operator drill-down."""\n        name = doc["name"]\n        oid = doc.get("_id", {}).get("$oid", "?")\n        techs = doc.get("techs", [])\n        stats = doc.get("stats", [])\n\n        by_state: dict[int, int] = defaultdict(int)\n        by_type: dict[str, int] = defaultdict(int)\n        records: list[str] = []\n        combos: set[tuple] = set()\n\n        for s in stats:\n            st = s.get("state", 0)\n            by_state[st] += 1\n            by_type[s.get("type", "?")] += 1\n            combo = (s.get("type"), s.get("tech"), s.get("channel"), s.get("domain"))\n            combos.add(combo)\n            state_label = {1: "pending", 2: "approved", 3: "published"}.get(st, str(st))\n            subs = s.get("subscribers", 0)\n            records.append(\n                f"  {s.get(\'type\', \'?\'):10s} {s.get(\'tech\', \'?\'):18s} "\n                f"{s.get(\'channel\', \'?\'):15s} {s.get(\'domain\', \'?\'):12s} "\n                f"{subs:>10,}  {state_label}"\n            )\n\n        # Gap analysis: only check techs that are actually used by this operator\n        # (from their stats or from their profile\'s first 3 technologies)\n        techs_in_use = sorted(set(s.get("tech") for s in stats)) or techs[:3]\n        if not techs_in_use:\n            techs_in_use = ["(unknown)"]\n\n        gaps: list[str] = []\n        for t in VALID_TYPES:\n            for tech in techs_in_use:\n                for ch in VALID_CHANNELS:\n                    for dom in VALID_DOMAINS:\n                        if (t, tech, ch, dom) not in combos:\n                            gaps.append(f"  {t}/{tech}/{ch}/{dom}")\n\n        state_names = {1: "pending", 2: "approved", 3: "published"}\n        state_fmt = ", ".join(\n            f"{state_names.get(k, str(k))}: {v}" for k, v in sorted(by_state.items())\n        ) or "none"\n\n        type_fmt = ", ".join(f"{k}: {v}" for k, v in sorted(by_type.items())) or "none"\n\n        lines = [\n            f"GBS STATUS: {name} ({country}) — {period}",\n            "",\n            f"ID:        {oid}",\n            f"Techs:     {\', \'.join(techs[:10])}{\'...\' if len(techs) > 10 else \'\'}",\n            f"Records:   {len(stats)} | Filled: {len(combos)} combos | Gaps: {len(gaps)}",\n            f"States:    {state_fmt}",\n            f"By type:   {type_fmt}",\n            f"Admin:     {_gbs_admin_url(oid)}",\n            "",\n        ]\n\n        if records:\n            lines.append("EXISTING RECORDS:")\n            lines.extend(records)\n            lines.append("")\n\n        if gaps:\n            lines.append(f"GAPS ({len(gaps)}):")\n            lines.extend(gaps[:20])\n            if len(gaps) > 20:\n                lines.append(f"  ... and {len(gaps) - 20} more")\n            lines.append("")\n\n        return "\\n".join(lines)\n\n'}]