from __future__ import annotations

from .rules import (
    detect_intent,
    detect_order_status,
    extract_image_urls,
    extract_size_pairs_m,
    has_map_or_political_risk,
    has_porn_risk,
    is_meaningless_short,
    requests_external_contact,
)


def tool_detect_intent(msg: str) -> str:
    """识别客户当前意图: image/pricing/greeting/external_contact/finish_or_quote_trigger/nonsense/unknown。"""
    return detect_intent(msg or "")


def tool_extract_image_urls(msg: str) -> list[str]:
    """提取消息中的图片 URL 列表。"""
    return extract_image_urls(msg or "")


def tool_detect_order_status(goods_order: str) -> str:
    """识别订单状态: paid/pending_payment/refund/unknown。"""
    return detect_order_status(goods_order or "")


def tool_extract_size_pairs(msg: str) -> list[tuple[float, float]]:
    """提取尺寸对，单位米。返回 [(w, h), ...]。"""
    return extract_size_pairs_m(msg or "")


def tool_detect_risk(msg: str, goods_name: str = "") -> dict:
    """检测风险：地图政治、黄暴。"""
    text = msg or ""
    gname = goods_name or ""
    return {
        "map_or_political": has_map_or_political_risk(text, gname),
        "porn": has_porn_risk(text),
    }


def tool_detect_external_contact(msg: str) -> bool:
    """检测是否索要外部联系方式（微信/QQ/手机号等）。"""
    return requests_external_contact(msg or "")


def tool_is_meaningless_short(msg: str) -> bool:
    """检测是否无意义短句（嗯/哦/ok等）。"""
    return is_meaningless_short(msg or "")
