#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ScanCodeImplInterface.py
@Description：
@Author：XSH
@Time：2025/11/11 12:52
@Department：研发部
@Copyright：©2025 乐辰生物
"""
import sys
import clr
import socket
import gc
import struct
from clr_loader.types                           import Assembly, ClrFunction    #
from PyQt5                                  import Qt                   #
from abc                                    import abstractmethod       #
from AppUtils.utils                         import *                    #
from AppSettings.Settings                   import *                    #
from AppInterfaces.ImplInterface            import ImplInterface        #
from AppContexts.SerialContext              import SerialContext        #
from AppCore.AppRequestModels.SerialRequest import SerialRequest        #

class ScanCodeImplInterface(ImplInterface):
    Manager     : 'IScanCodeInterface'   # 扫码器管理器
    Controller  : 'ScanCodeController'  # 扫码器控制器
    Parameter   : SerialContext
    _IsScanning : bool


    @property
    def isScanning(self) -> bool:
        return False if not self.hasIsScanning else self._IsScanning


    @property
    def parameter(self) -> SerialContext:
        return self.Parameter if self.hasParameter else None


    @property
    def manager(self) -> 'IScanCodeInterface':
        return self.Manager if self.hasManager else None

    @property
    def controller(self) -> 'ScanCodeController':
        return self.Controller if self.hasController else None

    @property
    def hasController(self) -> bool:
        return hasattr(self, 'Controller') and self.Controller is not None

    @property
    def hasIsScanning(self) -> bool:
        return hasattr(self, '_IsScanning') and isinstance(self._IsScanning, (bool, int))

    @property
    def hasManager(self) -> bool:
        return hasattr(self, 'Manager') and self.Manager is not None

    @property
    def hasParameter(self) -> bool:
        return hasattr(self, 'Parameter') and isinstance(self.Parameter, SerialContext)

    @abstractmethod
    def waitForScanning(self, timeout: int = 1500) -> bool:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def StartScanningCode(self) -> int:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def StopScanningCode(self, timeout: int = 1500) -> int:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def ReadScanningCode(self, timeout: int = 1500) -> str:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def setHostMode(self) -> int:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def getVERSION(self) -> int:
        raise RuntimeError('The object has not been instantiated', )

    @property
    @abstractmethod
    def isAvailable(self) -> bool:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def isValid(self) -> bool:
        return self.hasManager() and self.hasParameter()

    @abstractmethod
    def IsOpen(self) -> bool:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def isEnabled(self) -> bool:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def isDisable(self) -> bool:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def Open(self, timeOut: int = 1000) -> int:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def Close(self, timeOut: int = 1000) -> int:
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def initManager(self, context: object = None, **args):
        raise RuntimeError('The object has not been instantiated', )

    @abstractmethod
    def deleManager(self):
        raise RuntimeError('The object has not been instantiated', )

    def SendString(self, buffer: str, **args) -> int:
        return RECODE_FAILURE


    def SendBinary(self, buffer: (bytes, bytearray, Qt.QByteArray), **args) -> int:
        return RECODE_FAILURE


    def Send(self, buffer, **args) -> int:
        return RECODE_FAILURE


    def ReadBinary(self, **args) -> Qt.QByteArray:
        return Qt.QByteArray()


    def ReadString(self, **args) -> str:
        return None


    def Read(self, request: SerialRequest, **args) -> int:
        return RECODE_FAILURE

