#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: WebSocketContext.py
 @DateTime: 2025/4/8 10:59
 @SoftWare: PyCharm
 @Author  ：xsh
"""
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *


class WebSocketContext(ContextModelInterface):
    API         : str     # 接口名称
    Mode        : int     # 连接模式
    Address     : str     # 连接地址
    Port        : int     # 连接端口
    Descriptor  : int     # 套接字号
    IsOpen      : bool    # 连接状态
    __slots__ = (
        'API'          ,
        'Mode'         ,
        'Address'      ,
        'Port'         ,
        'Descriptor'   ,
        'IsOpen'       ,
    )
    __types__ = (
        str     ,
        int     ,
        str     ,
        int     ,
        int     ,
        bool    ,
    )
    def __init__(self, **args):
        super(WebSocketContext, self).__init__()
        self.initialization("网络连接上下文")
        self.initParameter(**args)






    @classmethod
    def instance(cls, **args) -> 'WebSocketContext':
        result: WebSocketContext = cls.__new__(cls)
        result.__init__(**args)
        return result

    def initParameter(self, **args):
        if not isinstance(args, dict):
            return
        self.API        = AppConvert.ObjectConvert(args.get('API'         , "ws://0.0.0.0:9991"), str )
        self.Mode       = AppConvert.ObjectConvert(args.get('Mode'        , 0                           ), int )
        self.Descriptor = AppConvert.ObjectConvert(args.get('Descriptor'  , 0                           ), int )
        self.IsOpen     = AppConvert.ObjectConvert(args.get('IsOpen'      , False                       ), bool)
        self.Port       = AppConvert.ObjectConvert(args.get('Descriptor'  , 9991                        ), int )
        self.Address    = ''
        self.Port       = 0

    def initValue(self):
        super(WebSocketContext, self).initValue()
        self.API        = "ws://0.0.0.0:9991"
        self.Port       = 9991
        self.Mode       = 0
        self.Descriptor = 0
        self.IsOpen     = False


