[{'Text': '        op = mongo.find_one_operator(operator, country)\n        if not op:\n            return f"Operator not found: \'{operator}\' in \'{country}\'. Check name and country match exactly."\n\n        operator_id = mongo._oid_from_doc(op)\n        technologies = op.get("technologies", [])\n\n        gv = mongo.find_global_variables_current()\n        current_period = gv.get("currentStatsPeriod", "unknown") if gv else "unknown"\n\n        existing = mongo.find_statistics(operator_id, period)\n\n        existing_combos = {\n            (s["type"], s["tech"], s["channel"], s["domain"]) for s in existing\n        }\n\n        # Group gaps by type for readability\n        gaps_by_type: dict[str, list[str]] = {}\n        total_gaps = 0\n        for t in VALID_TYPES:\n            type_gaps = []\n            for tech in technologies:\n                for ch in VALID_CHANNELS:\n                    for dom in VALID_DOMAINS:\n                        if (t, tech, ch, dom) not in existing_combos:\n                            type_gaps.append(f"    {tech} / {ch} / {dom}")\n            if type_gaps:\n                gaps_by_type[t] = type_gaps\n                total_gaps += len(type_gaps)\n\n        # State breakdown\n        state_names = {1: "pending", 2: "approved", 3: "published"}\n        by_state: dict[int, int] = {}\n        by_type: dict[str, int] = {}\n        for s in existing:\n            st = s.get("state", 1)\n            by_state[st] = by_state.get(st, 0) + 1\n            tp = s.get("type", "unknown")\n            by_type[tp] = by_type.get(tp, 0) + 1\n\n        # Staleness\n        dist = _quarter_distance(period, current_period)\n        if period == current_period:\n            staleness = "current"\n        elif dist is not None:\n            staleness = f"{dist} quarter{\'s\' if dist != 1 else \'\'} behind current ({current_period})"\n        else:\n            staleness = f"older than current ({current_period})"\n\n        # Build output\n        lines = [\n            f"GBS status: {operator} ({country}) — {period}",\n            f"operator_id: {operator_id}",\n            f"technologies: {\', \'.join(technologies)}",\n            "",\n            f"Existing: {len(existing)} records",\n        ]\n\n        if by_type:\n            lines.append(f"  by type: {\', \'.join(f\'{k}: {v}\' for k, v in sorted(by_type.items()))}")\n        if by_state:\n            lines.append(f"  by state: {\', \'.join(f\'{state_names.get(k, k)}: {v}\' for k, v in sorted(by_state.items()))}")\n\n        lines.extend([\n            "",\n            f"Staleness: {staleness}",\n            "",\n            f"Gaps ({total_gaps} missing combinations):",\n        ])\n\n        for gtype, glist in gaps_by_type.items():\n            lines.append(f"  {gtype} ({len(glist)}):")\n            lines.extend(glist)\n\n        if total_gaps == 0:\n            lines.append("  None — all combinations covered")\n\n        return "\\n".join(lines)\n\n    def _valid_period(p: str) -> bool:\n        """Check period matches format like \'2025Q1\'."""\n        import re\n        return bool(re.match(r"^\\d{4}Q[1-4]$", p))\n\n    def add_statistic(\n        type: str,\n        operator_id: str,\n        period: str,\n        tech: str,\n        channel: str,\n        domain: str,\n        subscribers: int,\n        is_estimate: bool = False,\n        restated: bool = False,\n        notes: str = "",\n        created_by: str = "gbs-agent",\n        ctx=None,\n    ) -> str:\n        """\n        Insert a Statistics (GBS) record with state: 1 (pending).\n\n        Operator name and country are auto-filled from the operator record to prevent mismatches.\n\n        Args:\n            type: broadband | mobile | iptv\n            operator_id: Operator ObjectId (from list_operators or get_gbs_status)\n            period: Quarter string (e.g. "2025Q1")\n            tech: Technology (must match operator\'s technologies)\n            channel: Infrastructure | Retail\n            domain: Residential | Business | Total\n            subscribers: Subscriber count (must be >= 0)\n            is_estimate: Whether value is estimated\n            restated: Whether value was restated\n            notes: Optional notes\n            created_by: Creator identifier (e.g. user email)\n\n        Returns:\n            Inserted record summary or error message.\n        """\n        if type not in VALID_TYPES:\n            return f"Invalid type: {type}. Must be one of {VALID_TYPES}"\n        if channel not in VALID_CHANNELS:\n            return f"Invalid channel: {channel}. Must be one of {VALID_CHANNELS}"\n        if domain not in VALID_DOMAINS:\n            return f"Invalid domain: {domain}. Must be one of {VALID_DOMAINS}"\n        if not _valid_object_id(operator_id):\n            return f"Invalid operator_id: must be 24 hex chars"\n        if not _valid_period(period):\n            return f"Invalid period: \'{period}\'. Must be format YYYYQN (e.g. \'2025Q1\')"\n        if subscribers < 0:\n            return f"Invalid subscribers: {subscribers}. Must be >= 0"\n\n        op = mongo.find_one_operator_by_id(operator_id)\n        if not op:\n            return f"Operator not found: {operator_id}"\n\n        op_name = op.get("name", "")\n        op_country = op.get("country", "")\n        techs = op.get("technologies", [])\n        tech_match = next((t for t in techs if t.lower() == tech.lower()), None)\n        if not tech_match:\n            return f"Tech \'{tech}\' not valid for operator \'{op_name}\'. Valid: {techs}"\n\n        # Check for duplicate (same operator, period, type, tech, channel, domain)\n        existing = mongo.find_statistics(operator_id, period)\n        for s in existing:\n            if (s.get("type") == type and s.get("tech") == tech_match\n                    and s.get("channel") == channel and s.get("domain") == domain):\n                eid = mongo._oid_from_doc(s)\n                return (f"Duplicate: statistic already exists for "\n                        f"{type}/{tech_match}/{channel}/{domain} in {period} "\n                        f"(id={eid}, state={s.get(\'state\', \'?\')}). Not inserted.")\n\n        doc = {\n            "type": type,\n            "country": op_country,\n            "operator": op_name,\n            "operatorId": operator_id,\n            "period": period,\n            "tech": tech_match,\n            "channel": channel,\n            "domain": domain,\n            "subscribers": subscribers,\n            "is_estimate": is_estimate,\n            "restated": restated,\n            "notes": notes or None,\n            "createdBy": created_by,\n        }\n        inserted_id = mongo.insert_one_statistic(doc)\n        return (f"Created statistic {inserted_id} (state: pending)\\n"\n                f"  {op_name} ({op_country}) | {period} | {type} | {tech_match} | "\n                f"{channel} | {domain} | subscribers={subscribers}")\n'}]