#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: SizeContext.py
 @DateTime: 2025/4/11 9:05
 @SoftWare: PyCharm
 @Author  ：xsh
"""
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *

class SizeContext(ContextModelInterface):
    Camera_SOURCE_W     : int
    Camera_SOURCE_H     : int
    RESPONSE_IMAGE_W    : int
    RESPONSE_IMAGE_H    : int
    VideoStream_W       : int
    VideoStream_H       : int
    PreviewImage_W      : int
    PreviewImage_H      : int
    MVideoStream_W      : int
    MVideoStream_H      : int
    MPreviewImage_W     : int
    MPreviewImage_H     : int
    SlideAreaImage_W    : int
    SlideAreaImage_H    : int
    ImageList_W         : int
    ImageList_H         : int
    DrawImage_W         : int
    DrawImage_H         : int
    CaseImage_W         : int
    CaseImage_H         : int
    def __init__(self, **args):
        super(SizeContext, self).__init__()
        self.initialization("")
        self.initParameter(**args)
    
    @classmethod
    def instance(cls, **args) -> 'SizeContext':
        result: cls = cls.__new__(cls)
        result.__init__(**args)
        return result
    
    def initParameter(self, **args):
        super(SizeContext, self).initParameter(**args)
        for index, _property in enumerate(self.__slots__):
            setattr(self, _property, AppConvert.ObjectConvert(
                args.get(_property, getattr(self, _property, None)),
                self.__types__[index]
            ))

    def UpdateMaxLocation(self, buffer: dict):
        self.as_field(buffer)



    def as_field(self, buffer: dict[str, object], is_primary: bool = True):
        primary: str
        index  : int
        keys: list[str] = 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 to_field(self, is_primary: bool = True) -> dict[str, object]:
        buffer: dict[str, object] = {}
        primary: str = ''
        for index, _property in enumerate(self.__slots__):
            buffer[_property] = getattr(self, _property, None)
        return buffer


    def initValue(self):
        super(SizeContext, self).initValue()
        self.Camera_SOURCE_W   = 2048
        self.Camera_SOURCE_H   = 2048 
        self.RESPONSE_IMAGE_W  = 512  
        self.RESPONSE_IMAGE_H  = 512  
        self.VideoStream_W     = 400
        self.VideoStream_H     = 400
        self.PreviewImage_W    = 800
        self.PreviewImage_H    = 800
        self.MVideoStream_W    = 400
        self.MVideoStream_H    = 300
        self.MPreviewImage_W   = 800
        self.MPreviewImage_H   = 600
        self.ImageList_W       = 256
        self.ImageList_H       = 256
        self.CaseImage_W       = 1024
        self.CaseImage_H       = 1024
        self.SlideAreaImage_W  = 7
        self.SlideAreaImage_H  = 11
        self.DrawImage_W       = 2448 // 3
        self.DrawImage_H       = 2048 // 3
    def DrawImageSize(self) -> (int, int):
        return self.DrawImage_W, self.DrawImage_H

    def SlideAreaImageSize(self) -> (int, int):
        return self.SlideAreaImage_W, self.SlideAreaImage_H
    def ImageListSize(self) -> (int, int):
        return self.ImageList_W, self.ImageList_H
    def PreviewImageSize(self) -> (int, int):
        return self.PreviewImage_W, self.PreviewImage_H
    def VideoStreamSize(self) -> (int, int):
        return self.VideoStream_W, self.VideoStream_H
    def RequestSize(self) -> (int, int):
        return self.RESPONSE_IMAGE_W, self.RESPONSE_IMAGE_H
    __slots__ = (
        'Camera_SOURCE_W'  ,
        'Camera_SOURCE_H'  ,
        'RESPONSE_IMAGE_W' ,
        'RESPONSE_IMAGE_H' ,
        'VideoStream_W'    ,
        'VideoStream_H'    ,
        'PreviewImage_W'   ,
        'PreviewImage_H'   ,
        'MVideoStream_W'   ,
        'MVideoStream_H'   ,
        'MPreviewImage_W'  ,
        'MPreviewImage_H'  ,
        'SlideAreaImage_W' ,
        'SlideAreaImage_H' ,
        'ImageList_W'      ,
        'ImageList_H'      ,
        'DrawImage_W'      ,
        'DrawImage_H'      ,
        'CaseImage_W'      ,
        'CaseImage_H'      ,
    )
    __types__ = (
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
        int ,
    )
        

