#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：SystemConfigInterface.py
@Description：
@Author：XSH
@Time：2025/11/11 11:54
@Department：研发部
@Copyright：©2025 乐辰生物
"""
import asyncio
from PyQt5 import Qt
from abc import abstractmethod
from AppInterfaces.ConfigInterface import ConfigInterface
from AppInterfaces.AppConfigInterfaces.ImageConfigInterface     import ImageConfigInterface
from AppInterfaces.AppConfigInterfaces.TrayConfigInterface      import TrayConfigInterface
class SystemConfigInterface(ConfigInterface):
    ID                                  : int                           # '系统数据序号　'
    ReceivedTails                       : bytes                         # '扫码结束标志　'
    ReceivedWaits                       : int                           # '接收扫码时长　'
    MaxWaitTimes                        : int                           # '扫码等待时长　'
    MinChamberNumber                    : int                           # '片仓最小组数　'
    MaxChamberNumber                    : int                           # '片仓最大组数　'
    MinRowNumber                        : int                           # '片仓最小行数　'
    MaxRowNumber                        : int                           # '片仓最大行数　'
    MinTrayRowNumber                    : int                           # '载玻台最小行数'
    MinTrayColNumber                    : int                           # '载玻台最小列数'
    MaxTrayRowNumber                    : int                           # '载玻台最大行数'
    MaxTrayColNumber                    : int                           # '载玻台最大列数'
    MaxTrayRowNumber20X                 : int                           # '载玻台最大行数'
    MaxTrayColNumber20X                 : int                           # '载玻台最大列数'
    MODBUS_POOL_LENGTH                  : int                           # '连接池连接数量'
    DebugMode                           : int                           # '仪器调试模式　'
    BuzzerMode                          : int                           # '蜂鸣器模式　　'
    IsLeiCa                             : int                           # '是否莱卡显微镜'
    EnglishMode                         : int                           # '英文模式　　　'
    WarningSpaceTimes                   : int                           # '告警间隔时长　'
    CameraName                          : str                           #
    ImageConfigure                      : ImageConfigInterface          #
    TrayConfigure                       : TrayConfigInterface           #
    AsyncioLoop                         : asyncio.AbstractEventLoop     #
    def getRowRange(self) -> (int, int):
        return self.MinRowNumber, self.MaxRowNumber

    def getChamberRange(self) -> (int, int):
        return self.MinChamberNumber, self.MaxChamberNumber

    def getChamberNumbers(self, chamber_number: int, row_number: int) -> (int, int):
        RowNumber: int
        ChamberNumber: int
        RowNumber = min(self.MaxRowNumber, max(self.MinRowNumber, row_number))
        ChamberNumber = min(self.MaxChamberNumber, max(self.MinChamberNumber, chamber_number))
        return ChamberNumber, RowNumber

    def getPointNumbers(self, row_number: int, col_number: int) -> (int, int):
        RowNumber: int
        ColNumber: int
        RowNumber = min(self.MaxTrayRowNumber, max(self.MinTrayRowNumber, row_number))
        ColNumber = min(self.MaxTrayColNumber, max(self.MinTrayColNumber, col_number))
        return RowNumber, ColNumber

    def getTrayScanRowRange(self) -> (int, int):
        return self.MinTrayRowNumber, self.MaxTrayRowNumber

    def getTrayScanColRange(self) -> (int, int):
        return self.MinTrayColNumber, self.MaxTrayColNumber

    @property
    @abstractmethod
    def getCameraName(self) -> str:
        pass

    @property
    @abstractmethod
    def camera_names(self) -> list[str]:
        pass

    @abstractmethod
    def setCameraName(self, value: str):
        pass

    @property
    @abstractmethod
    def isDebugMode(self) -> int:
        pass

    @abstractmethod
    def setDebugMode(self, enable: (bool, int)):
        pass

    @property
    @abstractmethod
    def isBuzzerMode(self) -> bool:
        pass

    @abstractmethod
    def setBuzzerMode(self, enable: (bool, int)):
        pass

    @property
    @abstractmethod
    def isEnglishMode(self) -> bool:
        pass

    @abstractmethod
    def setEnglishMode(self, enable: (bool, int)):
        pass

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

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

    @abstractmethod
    def WarningWaitTimes(self) -> int:
        pass

    @abstractmethod
    def setWarningWaitTimes(self, waittime: (float, int)):
        pass

    @abstractmethod
    def isLeiCaMicroscope(self) -> bool:
        pass

    @abstractmethod
    def setLeiCaMicroscope(self, enable: (bool, int)):
        pass












    __slots__ = (
        'ID'                    ,
        'ReceivedTails'         ,
        'ReceivedWaits'         ,
        'MaxWaitTimes'          ,
        'MinChamberNumber'      ,
        'MaxChamberNumber'      ,
        'MinRowNumber'          ,
        'MaxRowNumber'          ,
        'MinTrayRowNumber'      ,
        'MinTrayColNumber'      ,
        'MaxTrayRowNumber'      ,
        'MaxTrayColNumber'      ,
        'MaxTrayRowNumber20X'   ,
        'MaxTrayColNumber20X'   ,
        'MODBUS_POOL_LENGTH'    ,
        'DebugMode'             ,
        'BuzzerMode'            ,
        'EnglishMode'           ,
        'IsLeiCa'               ,
        'WarningSpaceTimes'     ,
        'CameraName'            ,
    )
    __types__ = (
        int    ,
        bytes  ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        str    ,
    )








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

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

    def setTrayConfigure(self, value):
        self.TrayConfigure = value if isinstance(value, TrayConfigInterface) else None

    def setImageConfigure(self, value):
        self.ImageConfigure = value if isinstance(value, ImageConfigInterface) else None

    @property
    def tray(self) -> TrayConfigInterface:
        return self.TrayConfigure if self.hasTrayConfigure else None

    @property
    def image(self) -> ImageConfigInterface:
        return self.ImageConfigure if self.hasImageConfigure else None





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

    @property
    def hasReceivedTails                       (self) -> bool:
        return hasattr(self, 'ReceivedTails'          ) and isinstance(self.ReceivedTails                       , (bytes, bytearray, Qt.QByteArray)  )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


    @property
    def hasCameraName(self) -> bool:
        return hasattr(self, 'CameraName') and isinstance(self.CameraName, str)

    @property
    def hasImageConfigure (self) -> bool:
        return hasattr(self, 'ImageConfigure') and isinstance(self.ImageConfigure, ImageConfigInterface)

    @property
    def hasTrayConfigure  (self) -> bool:
        return hasattr(self, 'TrayConfigure' ) and isinstance(self.TrayConfigure , TrayConfigInterface )


    @property
    def hasAsyncioLoop(self) -> bool:
        return hasattr(self, 'AsyncioLoop') and isinstance(self.AsyncioLoop, asyncio.AbstractEventLoop) and self.AsyncioLoop is not None

    @property
    def hasIsLeiCa(self) -> bool:
        return self.hasAttribute('IsLeiCa', (bool, int))

    @property
    def async_io_loop(self) -> asyncio.AbstractEventLoop:
        return self.AsyncioLoop if self.hasAsyncioLoop else None

    def setAsyncioLoop(self, value: asyncio.AbstractEventLoop):
        self.AsyncioLoop = value if isinstance(value, asyncio.AbstractEventLoop) else None

