#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：ControlFrameInterface.py
@Description：
@Author：XSH
@Time：2025/11/17 10:32
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5                              import Qt
from AppSettings.Settings               import *
from AppCore.Levels                     import *
from AppUtils.UiUtils                   import UiUtils
from AppInterfaces.UiInterface          import UiInterface
from AppInterfaces.ReaderInterfaces     import *
from AppInterfaces.ImplInterfaces       import *
from AppBackEnd.AppBusinessInterface    import AppBusinessInterface

class ControlFrameInterface(UiInterface):
    Business: AppBusinessInterface  #

    def initWidgetStyle(self):
        from AppUtils.UiUtils import UiUtils
        self.setStyleSheet(UiUtils.getTransparentStyle())



    def initBusiness   (self):
        if not self.hasBusiness:
            from AppBackEnd.AppScanningFlow import AppScanningFlow
            self.Business = AppScanningFlow.GetInstance()

    def isAvailable(self) -> bool:
        return self.hasBusiness and self.business.hasDevices

    @property
    def hasBusiness(self) -> bool:
        return hasattr(self, 'Business') and isinstance(self.Business, AppBusinessInterface)

    @property
    def business(self) -> AppBusinessInterface:
        return None if not self.hasBusiness else self.Business

    @property
    def camera(self) -> CameraReaderInterface:
        return None if not self.hasCamera else self.business.camera

    @property
    def motion(self) -> MotionReaderInterface:
        return None if not self.hasMotion else self.business.motion

    @property
    def scancode(self) -> ScanCodeReaderInterface:
        return None if not self.hasScanCode else self.business.scancode

    @property
    def webserver(self) -> WebReaderInterface:
        return None if not self.hasWebServer else self.business.webserver

    @property
    def axis_x(self) -> AxisImplInterface:
        return self.manipulator.axis_x if self.hasAxisZ else None

    @property
    def axis_y(self) -> AxisImplInterface:
        return self.manipulator.axis_y if self.hasAxisZ else None

    @property
    def axis_z(self) -> AxisImplInterface:
        return self.manipulator.axis_z if self.hasAxisZ else None

    @property
    def axis_h(self) -> HookImplInterface:
        return self.manipulator.axis_h if self.hasAxisH else None

    @property
    def hasAxisX(self) -> bool:
        return self.hasManipulator and self.manipulator.hasAxisX

    @property
    def hasAxisY(self) -> bool:
        return self.hasManipulator and self.manipulator.hasAxisY

    @property
    def hasAxisZ(self):
        return self.hasManipulator and self.manipulator.hasAxisZ

    @property
    def hasAxisH(self) -> bool:
        return self.hasManipulator and self.manipulator.hasAxisH

    @property
    def manipulator(self) -> ManipulatorReaderInterface:
        return None if not self.hasMotion else self.motion.manipulator

    @property
    def microscope(self) -> MicroscopeReaderInterface:
        return None if not self.hasMotion else self.motion.microscope

    @property
    def detection(self) -> DetectionImplInterface:
        return None if not self.hasManipulator else self.manipulator.detector

    @property
    def manager(self) -> ModBusPoolInterface:
        return None if not self.hasMotion else self.motion.manager

    @property
    def hasManipulator(self) -> bool:
        return self.hasMotion and self.motion.hasManipulator

    @property
    def hasMicroscope(self) -> bool:
        return self.hasMotion and self.motion.hasMicroscope

    @property
    def hasDetection(self) -> bool:
        return self.hasManipulator and self.manipulator.hasDetector

    @property
    def hasManagerPool(self) -> bool:
        return self.hasMotion and self.motion.hasManager

    @property
    def hasCamera(self) -> bool:
        return self.hasBusiness and self.business.hasCamera

    @property
    def hasMotion(self) -> bool:
        return self.hasBusiness and self.business.hasMotion

    @property
    def hasScanCode(self) -> bool:
        return self.hasBusiness and self.business.hasScanCode

    @property
    def hasWebServer(self) -> bool:
        return self.hasBusiness and self.business.hasWebServer

