#!D:/IDE/anaconda3/envs/Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName：SetCustomData.py
@Description：
@Author：XSH
@Time：2025/12/2 17:49
@Department：研发部
@Copyright：©2025 乐辰生物
"""
from PyQt5 import Qt
from abc import abstractmethod, abstractclassmethod, abstractstaticmethod
from AppInterfaces.utils                    import *
from AppSettings.utils                      import *
from AppCore.Requests                       import *
from AppInterfaces.Interfaces               import *
from AppCore.Levels                         import *
from AppUtils.utils                         import *
from AppBackEnd.WebBusinessInterface import WebBusinessInterface


class SetCustomData(Qt.QObject, WebBusinessInterface):
    def __init__(self, manager: WebReaderInterface = None, parent: Qt.QObject = None):
        super(SetCustomData, self).__init__(parent=parent)
        self.Manager = manager
        self.Initialization("SetCustomData", self, parent)

    def initWEBAPILevel(self):
        self.Level = WebAPILevel.setCustomData



    def Done(self, handler: WebClientInterface, **kwargs):
        isWrong: int = RECODE_FAILURE
        from AppCore.DBModels import CustomScanningModel, ChamberStatusModel
        try:
            self.Handler = handler
            request: Request = Request.APIInstance(self.Level)
            request.code = CODE_WARNING
            customData: list[list[dict[str, object]]] = kwargs.get("data", None)
            isCustomScanning: bool = isinstance(customData, (list, tuple))
            if isCustomScanning:
                CustomScanningModel.setCustomData(customData)
                ChamberStatusModel.setCustomData(customData)
                request.code = CODE_SUCCESS
            isWrong = self.WebSendFrame(request.toJson())
            if isCustomScanning:
                parameters: dict = {'isAuto': False}
                AppSlot.StartScanningSignal.emit(parameters)
        except Exception as e:

            AppUtils.print_Exception(e)
        return
    def WaitDone(self, handler: WebClientInterface, **kwargs) -> int:

        isWrong: int = RECODE_FAILURE
        from AppCore.DBModels import CustomScanningModel, ChamberStatusModel
        try:
            self.Handler = handler
            request: Request = Request.APIInstance(self.Level)
            request.code = CODE_WARNING
            customData: list[list[dict[str, object]]] = kwargs.get("data", None)
            isCustomScanning: bool = isinstance(customData, (list, tuple))
            if isCustomScanning:
                CustomScanningModel.setCustomData(customData)
                ChamberStatusModel.setCustomData(customData)
                request.code = CODE_SUCCESS
                isWrong = self.WebSendFrame(request.toJson())
                parameters: dict = {'isAuto': False}
                AppSlot.StartScanningSignal.emit(parameters)
                AppTimeLoop.processEvents(1000)


        except Exception as e:
            AppUtils.print_Exception(e)
        return isWrong



    """
    
    
    
    
    """













