"""受控拉取 — /v1/agent/fetch-request 已废止（D22 · 见 tenant_fetch + admin fetch）。"""

from __future__ import annotations

from typing import TYPE_CHECKING, Annotated, Any

from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel, Field

from niannian.http.core_auth import require_admin_owner

if TYPE_CHECKING:
    from niannian.client import NianNian


class AgentFetchRequestBody(BaseModel):
    username: str = Field(..., min_length=1)
    resource: str = Field(..., min_length=1)
    payload: dict[str, Any] = Field(default_factory=dict)


def create_agent_fetch_router(nn: NianNian) -> APIRouter:
    router = APIRouter(prefix="/v1/agent", tags=["agent"])

    @router.post("/fetch-request")
    def agent_fetch_request(
        body: AgentFetchRequestBody,
        _owner: Annotated[str, Depends(require_admin_owner)],
    ) -> dict[str, Any]:
        raise HTTPException(
            status_code=410,
            detail={
                "code": "agent_fetch_deprecated",
                "message": "use POST /v1/admin/users/{username}/fetch/{resource} and tenant fetch-response (D22)",
            },
        )

    return router
