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

"""
VWED统一对象模块系统
提供脚本中可使用的VWED.api、VWED.function等统一接口
"""

from utils.logger import get_logger

# 导入所有模块类
from .built_in_modules.api_module import VWEDApiModule
from .built_in_modules.function_module import VWEDFunctionModule
from .built_in_modules.event_module import VWEDEventModule
from .built_in_modules.timer_module import VWEDTimerModule
from .built_in_modules.log_module import VWEDLogModule
from .built_in_modules.task_module import VWEDTaskModule
from .built_in_modules.data_module import VWEDDataModule
from .built_in_modules.util_module import VWEDUtilModule
from .built_in_modules.device_module import VWEDDeviceModule
from .built_in_modules.robot_module import VWEDRobotModule
from .built_in_modules.location_module import VWEDLocationModule
from .built_in_modules.other_module import VWEDOtherModule
from .built_in_modules.file_distribution_module import VWEDFileDistributionModule
from .built_in_modules.system_thread_module import VWEDSystemThreadModule
from .built_in_modules.http_module import VWEDHttpModule
from .built_in_modules.fins_module import VWEDFinsModule
from .built_in_modules.melsec_module import VWEDMelsecModule
from .built_in_modules.modbus_module import VWEDModbusModule
from .built_in_modules.mqtt_module import VWEDMqttModule
from .built_in_modules.opc_ua_module import VWEDOpcUaModule
from .built_in_modules.websocket_module import VWEDWebSocketModule
from .built_in_modules.s7_module import VWEDS7Module


logger = get_logger("services.script_vwed_objects")


class VWEDObject:
    """VWED统一对象 - 脚本中的全局VWED变量"""
    
    def __init__(self, script_id: str):
        self.script_id = script_id
        
        # 初始化各模块
        self.api = VWEDApiModule(script_id)
        self.function = VWEDFunctionModule(script_id)
        self.event = VWEDEventModule(script_id)
        self.timer = VWEDTimerModule(script_id)
        self.log = VWEDLogModule(script_id)
        self.task = VWEDTaskModule(script_id)
        self.data = VWEDDataModule(script_id)
        self.util = VWEDUtilModule(script_id)
        self.device = VWEDDeviceModule(script_id)
        self.robot = VWEDRobotModule(script_id)
        self.location = VWEDLocationModule(script_id)
        self.other = VWEDOtherModule(script_id)
        self.file_distribution = VWEDFileDistributionModule(script_id)
        self.system_thread = VWEDSystemThreadModule(script_id)
        self.http = VWEDHttpModule(script_id)
        self.fins = VWEDFinsModule(script_id)
        self.melsec = VWEDMelsecModule(script_id)
        self.modbus = VWEDModbusModule(script_id)
        self.mqtt = VWEDMqttModule(script_id)
        self.opc_ua = VWEDOpcUaModule(script_id)
        self.websocket = VWEDWebSocketModule(script_id)
        self.s7 = VWEDS7Module(script_id)
    
    def get_script_id(self) -> str:
        """获取当前脚本ID"""
        return self.script_id


def create_vwed_object(script_id: str) -> VWEDObject:
    """创建VWED对象实例"""
    return VWEDObject(script_id)


# 导出外部使用的核心函数和类
__all__ = [
    'VWEDObject',
    'create_vwed_object'
]