#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName   : SpecimenContext.py
@Account    : Administrator
@Time       : 2025/10/14 14:42
@Author     : xsh
@Description: 
"""
from datetime import datetime
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *

class SpecimenContext(ContextModelInterface):
    ChamberGroupNumber              : int            # '片仓组号　　'
    ChamberRowNumber                : int            # '片仓行号　　'
    TrayNumber                      : int            # '托盘编号　　'
    CodeString                      : str            # '二维码编号　'
    SpecimenNumber                  : str            # '样本编号　　'
    SlideNumber                     : str            # '玻片编号　　'
    ObjectiveLevel                  : int            # '物镜类型　　'
    PreviewCount                    : int            # '预览图数量　'
    CollectCount                    : int            # '采集图数量　'
    StartScanningDateTime           : datetime       # '开始扫描时间'
    StopScanningDateTime            : datetime       # '结束扫描时间'

    def to_field(self) -> dict[str, object]:
        buffer: dict[str, object] = {}

        for index, _property in enumerate(self.__slots__):
            buffer[_property] = getattr(self, _property, None)
        return buffer

    def as_field(self, buffer: dict[str, object]):
        primary: str
        index  : int
        keys: list[str] = list(buffer.keys())
        for index, _property in enumerate(self.__slots__):
            if _property in keys:
                setattr(self, _property, AppConvert.ObjectConvert(buffer.get(_property, None), self.__types__[index]))

    def toTEXT(self) -> str:
        text: str = ''
        buffer: str
        for index, _property in enumerate(self.__slots__):
            try:
                buffer = AppConvert.ObjectConvert(getattr(self, _property, ''), str)
            except Exception as e:
                buffer = ''
            text += f'{buffer}\t'
        return text
    def toHEADER(self) -> str:
        text: str = '/*'
        buffer: str
        for index, _property in enumerate(self.__header__):
            text += f'{_property}\t'
        text += '*/'
        return text

    __slots__ = (
        'ChamberGroupNumber'    ,
        'ChamberRowNumber'      ,
        'TrayNumber'            ,
        'CodeString'            ,
        'SpecimenNumber'        ,
        'SlideNumber'           ,
        'ObjectiveLevel'        ,
        'PreviewCount'          ,
        'CollectCount'          ,
        'StartScanningDateTime' ,
        'StopScanningDateTime'  ,
    )

    __types__ = (
        int      ,
        int      ,
        int      ,
        str      ,
        str      ,
        str      ,
        int      ,
        int      ,
        int      ,
        datetime ,
        datetime ,
    )

    __header__ = (
        '片仓组号　　',
        '片仓行号　　',
        '托盘编号　　',
        '二维码编号　',
        '样本编号　　',
        '玻片编号　　',
        '物镜类型　　',
        '识别细胞数量',
        '采集细胞数量',
        '开始扫描时间',
        '结束扫描时间',
    )

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

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

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

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

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

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

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

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

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

    @property
    def hasStartScanningDateTime (self) -> bool:
        return hasattr(self, 'StartScanningDateTime') and isinstance(self.StartScanningDateTime , (datetime, Qt.QDateTime)    )

    @property
    def hasStopScanningDateTime  (self) -> bool:
        return hasattr(self, 'StopScanningDateTime' ) and isinstance(self.StopScanningDateTime  , (datetime, Qt.QDateTime)    )


