"""
find_agent 工具包

在此注册本 Agent 专属的工具。
"""
from __future__ import annotations

import sys
from collections.abc import Callable
from typing import Any

from agents.find_agent.support import (
    portrait as _portrait,
    qwen_video_analysis as _qwen_video_analysis,
    search_persistence as _search_persistence,
    video_discovery as _video_discovery,
)
from agents.find_agent.tools.batch_fetch_portraits import batch_fetch_portraits
from agents.find_agent.tools.batch_search_and_record import batch_search_and_record
from agents.find_agent.tools.batch_update_video_discovery_candidates import (
    batch_update_video_discovery_candidates,
)
from agents.find_agent.tools.douyin_detail import douyin_detail
from agents.find_agent.tools.douyin_search import douyin_search
from agents.find_agent.tools.douyin_search_tikhub import douyin_search_tikhub
from agents.find_agent.tools.douyin_user_videos import douyin_user_videos
from agents.find_agent.tools.get_account_fans_portrait import (
    get_account_fans_portrait,
)
from agents.find_agent.tools.get_content_fans_portrait import (
    get_content_fans_portrait,
)
from agents.find_agent.tools.normalize_age_portraits import normalize_age_portraits
from agents.find_agent.tools.query_video_discovery_state import (
    query_video_discovery_state,
)
from agents.find_agent.tools.update_video_discovery_run_status import (
    update_video_discovery_run_status,
)
from supply_agent.tools.registry import ToolRegistry

# 旧调用方的模块路径兼容。实现均已迁出 tools，且不会注册为 Agent 工具。
_LEGACY_MODULE_ALIASES = {
    "hotspot_profile": _portrait,
    "qwen_video_analyze": _qwen_video_analysis,
    "search_persistence": _search_persistence,
    "video_discovery_store": _video_discovery,
}
for _legacy_name, _support_module in _LEGACY_MODULE_ALIASES.items():
    sys.modules.setdefault(
        f"{__name__}.{_legacy_name}",
        _support_module,
    )

ALL_TOOLS: list[Callable[..., Any]] = [
    batch_search_and_record,
    douyin_search,
    douyin_search_tikhub,
    douyin_user_videos,
    douyin_detail,
    get_content_fans_portrait,
    get_account_fans_portrait,
    batch_fetch_portraits,
    normalize_age_portraits,
    batch_update_video_discovery_candidates,
    update_video_discovery_run_status,
    query_video_discovery_state,
]

__all__ = [
    "ALL_TOOLS",
    "batch_search_and_record",
    "douyin_search",
    "douyin_search_tikhub",
    "douyin_user_videos",
    "douyin_detail",
    "get_content_fans_portrait",
    "get_account_fans_portrait",
    "batch_fetch_portraits",
    "normalize_age_portraits",
    "batch_update_video_discovery_candidates",
    "update_video_discovery_run_status",
    "query_video_discovery_state",
    "register_all_tools",
]


def register_all_tools(registry: ToolRegistry) -> ToolRegistry:
    """将 find_agent 包内的所有工具注册到 ToolRegistry。"""
    return registry.from_decorated(*ALL_TOOLS)
