#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ManipulatorConfigureInterface.py
@Description：
@Author：XSH
@Time：2025/11/11 19:04
@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

class ManipulatorConfigureInterface(ContextModelInterface):
    ModBusConfig    : ModBusContext                        #
    AxisXConfig     : AxisRegisterContext                  #
    AxisYConfig     : AxisRegisterContext                  #
    AxisZConfig     : AxisRegisterContext                  #
    AxisHConfig     : HookRegisterContext                  #
    ScanXConfig     : AxisRegisterContext                  #
    ScanYConfig     : AxisRegisterContext                  #
    SlowXConfig     : AxisRegisterContext                  #
    SlowYConfig     : AxisRegisterContext                  #
    DropXConfig     : AxisRegisterContext                  #
    DropYConfig     : AxisRegisterContext                  #
    DetectionConfig : DetectionRegisterContext             #

    @property
    def ModBus    (self) -> ModBusContext   :
        return None if not self.hasModBusConfig    else self.ModBusConfig

    @property
    def AxisX     (self) -> AxisRegisterContext     :
        return None if not self.hasAxisXConfig     else self.AxisXConfig

    @property
    def AxisY     (self) -> AxisRegisterContext     :
        return None if not self.hasAxisYConfig     else self.AxisYConfig

    @property
    def AxisZ     (self) -> AxisRegisterContext     :
        return None if not self.hasAxisZConfig     else self.AxisZConfig

    @property
    def AxisH     (self) -> HookRegisterContext     :
        return None if not self.hasAxisHConfig     else self.AxisHConfig

    @property
    def ScanX     (self) -> AxisRegisterContext     :
        return None if not self.hasScanXConfig     else self.ScanXConfig

    @property
    def ScanY     (self) -> AxisRegisterContext     :
        return None if not self.hasScanYConfig     else self.ScanYConfig

    @property
    def SlowX     (self) -> AxisRegisterContext     :
        return None if not self.hasSlowXConfig     else self.SlowXConfig

    @property
    def SlowY     (self) -> AxisRegisterContext     :
        return None if not self.hasSlowYConfig     else self.SlowYConfig

    @property
    def DropX     (self) -> AxisRegisterContext     :
        return None if not self.hasDropXConfig     else self.DropXConfig

    @property
    def DropY     (self) -> AxisRegisterContext     :
        return None if not self.hasDropYConfig     else self.DropYConfig

    @property
    def Detection (self) -> DetectionRegisterContext:
        return None if not self.hasDetectionConfig else self.DetectionConfig

    @property
    def hasModBusConfig    (self) -> bool:
        return hasattr(self, 'ModBusConfig'   ) and isinstance(self.ModBusConfig   , ModBusContext   )

    @property
    def hasAxisXConfig     (self) -> bool:
        return hasattr(self, 'AxisXConfig'    ) and isinstance(self.AxisXConfig    , AxisRegisterContext     )

    @property
    def hasAxisYConfig     (self) -> bool:
        return hasattr(self, 'AxisYConfig'    ) and isinstance(self.AxisYConfig    , AxisRegisterContext     )

    @property
    def hasAxisZConfig     (self) -> bool:
        return hasattr(self, 'AxisZConfig'    ) and isinstance(self.AxisZConfig    , AxisRegisterContext     )

    @property
    def hasAxisHConfig     (self) -> bool:
        return hasattr(self, 'AxisHConfig'    ) and isinstance(self.AxisHConfig    , HookRegisterContext     )

    @property
    def hasScanXConfig     (self) -> bool:
        return hasattr(self, 'ScanXConfig'    ) and isinstance(self.ScanXConfig    , AxisRegisterContext     )

    @property
    def hasScanYConfig     (self) -> bool:
        return hasattr(self, 'ScanYConfig'    ) and isinstance(self.ScanYConfig    , AxisRegisterContext     )

    @property
    def hasSlowXConfig     (self) -> bool:
        return hasattr(self, 'SlowXConfig'    ) and isinstance(self.SlowXConfig    , AxisRegisterContext     )

    @property
    def hasSlowYConfig     (self) -> bool:
        return hasattr(self, 'SlowYConfig'    ) and isinstance(self.SlowYConfig    , AxisRegisterContext     )

    @property
    def hasDropXConfig     (self) -> bool:
        return hasattr(self, 'DropXConfig'    ) and isinstance(self.DropXConfig    , AxisRegisterContext     )

    @property
    def hasDropYConfig     (self) -> bool:
        return hasattr(self, 'DropYConfig'    ) and isinstance(self.DropYConfig    , AxisRegisterContext     )

    @property
    def hasDetectionConfig (self) -> bool:
        return hasattr(self, 'DetectionConfig') and isinstance(self.DetectionConfig, DetectionRegisterContext)

    @abstractmethod
    def  initModBusConfig    (self):
        pass

    @abstractmethod
    def  initAxisXConfig     (self):
        pass

    @abstractmethod
    def  initAxisYConfig     (self):
        pass

    @abstractmethod
    def  initAxisZConfig     (self):
        pass

    @abstractmethod
    def  initAxisHConfig     (self):
        pass

    @abstractmethod
    def  initScanXConfig     (self):
        pass

    @abstractmethod
    def  initScanYConfig     (self):
        pass

    @abstractmethod
    def  initSlowXConfig     (self):
        pass

    @abstractmethod
    def  initSlowYConfig     (self):
        pass

    @abstractmethod
    def  initDropXConfig     (self):
        pass

    @abstractmethod
    def  initDropYConfig     (self):
        pass

    @abstractmethod
    def  initDetectionConfig (self):
        pass




    __slots__ = (
        'ModBusConfig'   ,
        'AxisXConfig'    ,
        'AxisYConfig'    ,
        'AxisZConfig'    ,
        'AxisHConfig'    ,
        'ScanXConfig'    ,
        'ScanYConfig'    ,
        'SlowXConfig'    ,
        'SlowYConfig'    ,
        'DropXConfig'    ,
        'DropYConfig'    ,
        'DetectionConfig',
    )
    __types__ = (
        ModBusContext    ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        AxisContext      ,
        DetectionContext ,
    )

    def serialize(self) -> dict[str, object]:
        buffer: dict[str, object] = {
            'ModBusConfig'   : self.ModBusConfig   .serialize(),
            'AxisXConfig'    : self.AxisXConfig    .serialize(),
            'AxisYConfig'    : self.AxisYConfig    .serialize(),
            'AxisZConfig'    : self.AxisZConfig    .serialize(),
            'AxisHConfig'    : self.AxisHConfig    .serialize(),
            'ScanXConfig'    : self.ScanXConfig    .serialize(),
            'ScanYConfig'    : self.ScanYConfig    .serialize(),
            'SlowXConfig'    : self.SlowXConfig    .serialize(),
            'SlowYConfig'    : self.SlowYConfig    .serialize(),
            'DropXConfig'    : self.DropXConfig    .serialize(),
        }

        return buffer

    def deserialize(self, buffer: dict[str, object]):
        if not isinstance(buffer, dict):
            return
        self.ModBusConfig       .deserialize(buffer.get('ModBusConfig'   , None))
        self.AxisXConfig        .deserialize(buffer.get('AxisXConfig'    , None))
        self.AxisYConfig        .deserialize(buffer.get('AxisYConfig'    , None))
        self.AxisZConfig        .deserialize(buffer.get('AxisZConfig'    , None))
        self.AxisHConfig        .deserialize(buffer.get('AxisHConfig'    , None))
        self.ScanXConfig        .deserialize(buffer.get('ScanXConfig'    , None))
        self.ScanYConfig        .deserialize(buffer.get('ScanYConfig'    , None))
        self.SlowXConfig        .deserialize(buffer.get('SlowXConfig'    , None))
        self.SlowYConfig        .deserialize(buffer.get('SlowYConfig'    , None))
        self.DropXConfig        .deserialize(buffer.get('DropXConfig'    , None))

    def asYaml(self, buffer: str):
        data_buffer: dict[str, object] = ConvertUtils.asYaml(buffer)
        if not isinstance(data_buffer, dict):
            return
        self.ModBusConfig       .deserialize(data_buffer.get('ModBusConfig'   , None))
        self.AxisXConfig        .deserialize(data_buffer.get('AxisXConfig'    , None))
        self.AxisYConfig        .deserialize(data_buffer.get('AxisYConfig'    , None))
        self.AxisZConfig        .deserialize(data_buffer.get('AxisZConfig'    , None))
        self.AxisHConfig        .deserialize(data_buffer.get('AxisHConfig'    , None))
        self.ScanXConfig        .deserialize(data_buffer.get('ScanXConfig'    , None))
        self.ScanYConfig        .deserialize(data_buffer.get('ScanYConfig'    , None))
        self.SlowXConfig        .deserialize(data_buffer.get('SlowXConfig'    , None))
        self.SlowYConfig        .deserialize(data_buffer.get('SlowYConfig'    , None))
        self.DropXConfig        .deserialize(data_buffer.get('DropXConfig'    , None))





    def toYaml(self) -> str:
        buffer: dict[str, object] = {}
        buffer['ModBusConfig'   ] = self.ModBusConfig      .serialize()
        buffer['AxisXConfig'    ] = self.AxisXConfig       .serialize()
        buffer['AxisYConfig'    ] = self.AxisYConfig       .serialize()
        buffer['AxisZConfig'    ] = self.AxisZConfig       .serialize()
        buffer['AxisHConfig'    ] = self.AxisHConfig       .serialize()
        buffer['ScanXConfig'    ] = self.ScanXConfig       .serialize()
        buffer['ScanYConfig'    ] = self.ScanYConfig       .serialize()
        buffer['SlowXConfig'    ] = self.SlowXConfig       .serialize()
        buffer['SlowYConfig'    ] = self.SlowYConfig       .serialize()
        buffer['DropXConfig'    ] = self.DropXConfig       .serialize()





        return ConvertUtils.toYaml(buffer)


