#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ContextConfigureInterface.py
@Description：
@Author：XSH
@Time：2025/11/11 19:00
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5 import Qt
from abc import abstractmethod
from AppInterfaces.ModelInterface   import ContextModelInterface
from AppContexts.Contexts           import *
from AppUtils.ConvertUtils          import ConvertUtils
from AppUtils.AppConvert            import AppConvert
from AppInterfaces.AppConfigInterfaces.ManipulatorConfigureInterface import ManipulatorConfigureInterface
class ContextConfigureInterface(ContextModelInterface):
    ManipulatorConfig   : ManipulatorConfigureInterface     #
    CameraConfig        : CameraContext                     #
    MicroscopeConfig    : MicroscopeContext                 #
    LMicroscopeConfig   : LeiCaContext                      #
    ZMicroscopeConfig   : ZeissContext                      #
    CodeScanningConfig  : SerialContext                     #
    SocketConfig        : SocketContext                     #
    WebConfig           : WebSocketContext                  #
    DBConfig            : DBContext                         #
    PathConfig          : PathContext                       #
    ClassifierConfig    : ClassifierContext                 #

    @property
    def Manipulator    (self) -> ManipulatorConfigureInterface:
        return None if not self.hasManipulatorConfig    else self.ManipulatorConfig

    @property
    def Camera         (self) -> CameraContext                :
        return None if not self.hasCameraConfig         else self.CameraConfig

    @property
    def Microscope     (self) -> MicroscopeContext            :
        return None if not self.hasMicroscopeConfig     else self.MicroscopeConfig


    @property
    def CodeScanning   (self) -> SerialContext                :
        return None if not self.hasCodeScanningConfig   else self.CodeScanningConfig

    @property
    def Socket         (self) -> SocketContext                :
        return None if not self.hasSocketConfig         else self.SocketConfig

    @property
    def WebSocket      (self) -> WebSocketContext             :
        return None if not self.hasWebConfig            else self.WebConfig

    @property
    def DB             (self) -> DBContext                    :
        return None if not self.hasDBConfig             else self.DBConfig

    @property
    def Path           (self) -> PathContext                  :
        return None if not self.hasPathConfig           else self.PathConfig

    @property
    def Classifier(self) -> ClassifierContext:
        return None if not self.hasClassifierConfig else self.ClassifierConfig

    @property
    def LeiCaMicroscope(self) -> LeiCaContext:
        return None if not self.hasLMicroscopeConfig else self.LMicroscopeConfig

    @property
    def ZeissMicroscope(self) -> ZeissContext:
        return None if not self.hasZMicroscopeConfig else self.ZMicroscopeConfig

    @property
    def hasLMicroscopeConfig   (self) -> bool:
        return hasattr(self, 'LMicroscopeConfig'       ) and isinstance(self.LMicroscopeConfig  , LeiCaContext                 )

    @property
    def hasManipulatorConfig   (self) -> bool:
        return hasattr(self, 'ManipulatorConfig'     ) and isinstance(self.ManipulatorConfig   , ManipulatorConfigureInterface )

    @property
    def hasCameraConfig        (self) -> bool:
        return hasattr(self, 'CameraConfig'          ) and isinstance(self.CameraConfig        , CameraContext                 )

    @property
    def hasMicroscopeConfig    (self) -> bool:
        return hasattr(self, 'MicroscopeConfig'      ) and isinstance(self.MicroscopeConfig    , MicroscopeContext             )

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

    @property
    def hasSocketConfig        (self) -> bool:
        return hasattr(self, 'SocketConfig'          ) and isinstance(self.SocketConfig        , SocketContext                 )

    @property
    def hasWebConfig           (self) -> bool:
        return hasattr(self, 'WebConfig'             ) and isinstance(self.WebConfig           , WebSocketContext              )

    @property
    def hasDBConfig            (self) -> bool:
        return hasattr(self, 'DBConfig'              ) and isinstance(self.DBConfig            , DBContext                     )

    @property
    def hasPathConfig          (self) -> bool:
        return hasattr(self, 'PathConfig'            ) and isinstance(self.PathConfig          , PathContext                   )

    @property
    def hasClassifierConfig    (self) -> bool:
        return hasattr(self, 'ClassifierConfig') and isinstance(self.ClassifierConfig, ClassifierContext)

    @property
    def hasZMicroscopeConfig(self) -> bool:
        return hasattr(self, 'ZMicroscopeConfig') and isinstance(self.ZMicroscopeConfig, ZeissContext)

    def toYaml(self) -> str:
        buffer: dict[str, object]  = {}
        value: ContextModelInterface
        for index, _property in enumerate(self.__slots__):
            value = getattr(self, _property, None)
            if isinstance(value, ContextModelInterface):
                buffer[f'{_property}'] = value.serialize()
        return ConvertUtils.toYaml(buffer)

    def asYaml(self, buffer: str):
        buffer: dict[str, object] = ConvertUtils.asYaml(buffer)
        value: ContextModelInterface
        for key in self.__slots__:
            value = getattr(self, key, None)
            if isinstance(value, ContextModelInterface):
                value.deserialize(buffer.get(key, {}))

    @abstractmethod
    def initManipulatorConfig   (self):
        pass

    @abstractmethod
    def initCameraConfig        (self):
        pass

    @abstractmethod
    def initMicroscopeConfig    (self):
        pass

    @abstractmethod
    def initCodeScanningConfig  (self):
        pass

    @abstractmethod
    def initSocketConfig        (self):
        pass

    @abstractmethod
    def initWebConfig           (self):
        pass

    @abstractmethod
    def initDBConfig            (self):
        pass

    @abstractmethod
    def initPathConfig          (self):
        pass

    @abstractmethod
    def initClassifierConfig    (self):
        pass


    @abstractmethod
    def initLeiCaMicroscope(self):
        pass

    @abstractmethod
    def initZeissMicroscope(self):
        pass



    __slots__ = (
        'ManipulatorConfig'                 ,
        'CameraConfig'                      ,
        'MicroscopeConfig'                  ,
        'LMicroscopeConfig'                 ,
        'CodeScanningConfig'                ,
        'SocketConfig'                      ,
        'WebConfig'                         ,
        'DBConfig'                          ,
        'PathConfig'                        ,
        'ClassifierConfig'                  ,
    )
    __types__ = (
        ManipulatorConfigureInterface       ,
        CameraContext                       ,
        MicroscopeContext                   ,
        LeiCaContext                        ,
        SerialContext                       ,
        SocketContext                       ,
        WebSocketContext                    ,
        DBContext                           ,
        PathContext                         ,
        ClassifierContext                   ,
    )