"""
健康检查和测试相关的API端点。
"""
from flask import Blueprint, jsonify

from core.app_state import is_real_mode, get_trader, logger

health_bp = Blueprint('health_routes', __name__, url_prefix='/yu')

@health_bp.route("/healthcheck", methods=["GET"])
def health_check():
    """健康检查端点，检查交易系统连接状态。"""
    if is_real_mode():
        trader = get_trader()
        if trader and not trader.is_available():
            return jsonify({
                "status": "error",
                "message": trader.connection_error_message or "交易系统连接失败"
            }), 503
    return jsonify({"status": "ok"}), 200

@health_bp.route("/test", methods=["GET"])
def test_route():
    """测试路由，用于验证API路由前缀和基本连通性。"""
    logger.info("Test route accessed.")
    return jsonify({"success": True, "message": "API路由前缀验证成功"}), 200 