# @File: backend/routers/uptimerobot_mcp.py
# @Desc: Admin endpoints that expose UptimeRobot's Model Context Protocol
#        integration (https://mcp.uptimerobot.com/mcp). Lets admins:
#          * fetch the ready-to-copy ``claude_desktop_config.json`` block,
#          * see whether the master UptimeRobot API key is configured,
#          * run a lightweight connectivity probe against the MCP endpoint,
#          * read a curated list of MCP capabilities + sample prompts.
#
# Mounted at ``/api/v1/admin/uptimerobot/mcp/*`` so it lives alongside the
# existing UptimeRobot admin surface and reuses the same auth guard.
from __future__ import annotations

import logging

from dependencies.auth import get_admin_user
from fastapi import APIRouter, Depends
from schemas.auth import UserResponse
from services.uptimerobot.mcp import get_mcp_config_payload, probe_mcp_endpoint

logger = logging.getLogger(__name__)

router = APIRouter(
    prefix="/api/v1/admin/uptimerobot/mcp",
    tags=["uptimerobot-admin-mcp"],
)


@router.get("/config")
async def admin_get_mcp_config(
    current_user: UserResponse = Depends(get_admin_user),
) -> dict:
    """Return the MCP integration payload (endpoint, auth headers, ready-to-
    copy JSON config, capability list, sample prompts). Admin-only."""
    return await get_mcp_config_payload()


@router.post("/test")
async def admin_test_mcp_endpoint(
    current_user: UserResponse = Depends(get_admin_user),
) -> dict:
    """Probe the public MCP endpoint using the stored master API key.

    Returns ``{ ok, http_status, error_class?, error_message?, ... }``.
    """
    return await probe_mcp_endpoint()