#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ScanCodeReaderInterface.py
@Description：
@Author：XSH
@Time：2025/11/11 15:03
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5 import Qt
from abc import abstractmethod
from AppInterfaces.AppImplInterfaces.ScanCodeImplInterface import ScanCodeImplInterface, SerialContext
from AppInterfaces.ReaderInterface import ReaderInterface


class ScanCodeReaderInterface(ReaderInterface):
    Manager     : ScanCodeImplInterface #
    Parameter   : SerialContext         #
    @property
    def hasManager(self) -> bool:
        return hasattr(self, 'Manager') and self.Manager is not None and isinstance(self.Manager, ScanCodeImplInterface)

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

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

    def setParameter(self, value):
        self.Parameter = value if isinstance(value, SerialContext) else None

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

    @property
    @abstractmethod
    def isAvailable(self) -> bool:
        raise Exception('Interface Instance error')

    @property
    @abstractmethod
    def isValid(self) -> bool:
        raise Exception('Interface Instance error')

    @property
    @abstractmethod
    def IsOpen(self) -> bool:
        raise Exception('Interface Instance error')

    @abstractmethod
    def Open(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def Close(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def initManager(self, **args):
        raise Exception('Interface Instance error')

    @abstractmethod
    def deleManager(self, **args):
        raise Exception('Interface Instance error')

    @abstractmethod
    def Transmit(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def Received(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def Send(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def Read(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def WaitDone(self, **args):
        raise Exception('Interface Instance error')

    def ReOpen(self, timeOut: int = 1000, **args) -> int:
        self.Close(timeOut=timeOut, **args)
        return self.Open(timeOut=timeOut, **args)

    @abstractmethod
    def initContext(self):
        raise Exception('Interface Instance error')

    @abstractmethod
    def setHostMode(self) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def getVERSION(self) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def waitForScanning(self, timeout: int = 1500) -> bool:
        raise Exception('Interface Instance error')

    @abstractmethod
    def waithome(self, **args) -> int:
        pass

    @abstractmethod
    def StartScanningCode(self) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def StopScanningCode(self, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def ReadQCode(self, waittime: int = 200) -> str:
        raise Exception('Interface Instance error')
    @abstractmethod
    def ReadScanningCode(self, timeout: int = 1500) -> str:
        raise Exception('Interface Instance error')

    @abstractmethod
    def SendString(self, buffer: str, **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def SendBinary(self, buffer: (bytes, bytearray, Qt.QByteArray), **args) -> int:
        raise Exception('Interface Instance error')

    @abstractmethod
    def ReadString(self, **args) -> str:
        raise Exception('Interface Instance error')

    @abstractmethod
    def ReadBinary(self) -> Qt.QByteArray:
        raise Exception('Interface Instance error')