#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
VWED.function 模块 - 自定义函数注册
"""

from typing import Dict, Callable, List
from ..script_registry_service import get_global_registry


class VWEDFunctionModule:
    """VWED.function 模块 - 自定义函数注册"""
    
    def __init__(self, script_id: str):
        self.script_id = script_id
        self.registry = get_global_registry()
    
    def register(self, name: str, handler: Callable = None, description: str = "", 
                params: Dict = None, parameters: List[Dict] = None, 
                return_schema: Dict = None, tags: List[str] = None):
        """分离式自定义函数注册
        
        使用方式：
        VWED.function.register(
            name="simple_add",
            handler=simple_add,
            description="简单加法函数",
            params={"a": 0, "b": 0}  # 简化的参数定义
        )
        """
        if handler is None:
            raise ValueError("handler参数不能为空")
            
        self.registry.register_function(
            name=name,
            handler=handler,
            script_id=self.script_id,
            description=description,
            params=params,  # 传递简化的参数格式
            parameters=parameters,
            return_schema=return_schema,
            tags=tags
        )
        return handler