#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：ImageConfigModel.py\n
 @DateTime: 2025/7/3 10:16\n
 @Author  ：xsh
"""
from PyQt5 import Qt
from datetime import datetime, date
import copy
from AppCore.AppDBModels.CoreModel import (CoreModel, DBManager, dbController)
from sqlalchemy.orm import declarative_base, mapper, sessionmaker, Session
from sqlalchemy.orm import (declarative_base, Mapped, mapped_column, relationship, mapper, sessionmaker)
from sqlalchemy import Table, Engine, create_engine, Column, ForeignKey, and_, or_, insert, delete, update, select, func, ColumnElement,distinct
from sqlalchemy.types import (Text, VARCHAR, REAL, Float, Integer, String, SmallInteger, DateTime, Date, ARRAY,Boolean, JSON)
from sqlalchemy.orm.decl_api import DeclarativeBase, MetaData
from AppUtils.utils import *
from AppCore.Levels import *

class ImageConfigModel(CoreModel):
    __tablename__ = 't_ImageConfigModel'
    ID                  : Mapped[int ] = mapped_column(primary_key=True   , nullable=False)
    VideoStream_W       : Mapped[int ] = mapped_column(default=400        , nullable=True , doc='实时画面显示宽度', comment='实时画面显示宽度')
    VideoStream_H       : Mapped[int ] = mapped_column(default=400        , nullable=True , doc='实时画面显示宽度', comment='实时画面显示宽度')
    PreviewImage_W      : Mapped[int ] = mapped_column(default=800        , nullable=True , doc='右下小框显示宽度', comment='右下小框显示宽度')
    PreviewImage_H      : Mapped[int ] = mapped_column(default=800        , nullable=True , doc='右下小框显示宽度', comment='右下小框显示宽度')
    MVideoStream_W      : Mapped[int ] = mapped_column(default=400        , nullable=True , doc='实时画面显示宽度', comment='实时画面显示宽度')
    MVideoStream_H      : Mapped[int ] = mapped_column(default=300        , nullable=True , doc='实时画面显示宽度', comment='实时画面显示宽度')
    MPreviewImage_W     : Mapped[int ] = mapped_column(default=800        , nullable=True , doc='右下小框显示宽度', comment='右下小框显示宽度')
    MPreviewImage_H     : Mapped[int ] = mapped_column(default=600        , nullable=True , doc='右下小框显示宽度', comment='右下小框显示宽度')
    SlideAreaImage_W    : Mapped[int ] = mapped_column(default=7          , nullable=True , doc='平扫图像显示宽度', comment='平扫图像显示宽度')
    SlideAreaImage_H    : Mapped[int ] = mapped_column(default=11         , nullable=True , doc='平扫图像显示高度', comment='平扫图像显示高度')
    ImageList_W         : Mapped[int ] = mapped_column(default=256        , nullable=True , doc='核型小图显示宽度', comment='核型小图显示宽度')
    ImageList_H         : Mapped[int ] = mapped_column(default=256        , nullable=True , doc='核型小图显示高度', comment='核型小图显示高度')
    DrawImage_W         : Mapped[int ] = mapped_column(default=600        , nullable=True , doc='调试界面显示宽度', comment='调试界面显示宽度')
    DrawImage_H         : Mapped[int ] = mapped_column(default=600        , nullable=True , doc='调试界面显示宽度', comment='调试界面显示宽度')
    CaseImage_W         : Mapped[int ] = mapped_column(default=1024       , nullable=True , doc='核型大图显示宽度', comment='核型大图显示宽度')
    CaseImage_H         : Mapped[int ] = mapped_column(default=1024       , nullable=True , doc='核型大图显示宽度', comment='核型大图显示宽度')
    def __init__(self, **args):
        super(ImageConfigModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    @classmethod
    def UpdateMaxLocation(cls):
        from AppSettings.AppSetting import AppSetting, AppConfig
        item: cls = cls.first()
        if item is not None:
            AppConfig.sizeConfig.UpdateMaxLocation(item.to_field(False))

    def initValue(self):
        super(ImageConfigModel, self).initValue()
        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.SlideAreaImage_W     = 7      #
        self.SlideAreaImage_H     = 11     #
        self.ImageList_W          = 256    #
        self.ImageList_H          = 256    #
        self.DrawImage_W          = 600    #
        self.DrawImage_H          = 600    #
        self.CaseImage_W          = 1024   #
        self.CaseImage_H          = 1024   #


    @classmethod
    def default_config(cls):
        result: cls = cls.__new__(cls)
        result.__init__()
        result.initValue()
        return result

    @classmethod
    def initModels(cls):
        return [cls.instance(ID=1)]

    @classmethod
    def VideoStreamSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.VideoStream_W, model.VideoStream_H

    @classmethod
    def PreviewImageSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.PreviewImage_W, model.PreviewImage_H

    @classmethod
    def MVideoStreamSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.MVideoStream_W, model.MVideoStream_H

    @classmethod
    def MPreviewImageSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.MPreviewImage_W, model.MPreviewImage_H
    @classmethod
    def ImageListSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.ImageList_W, model.ImageList_H

    @classmethod
    def SlideAreaImageSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.SlideAreaImage_W, model.SlideAreaImage_H

    @classmethod
    def DrawImageSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.DrawImage_W, model.DrawImage_H

    @classmethod
    def CaseImageSize(cls) -> (int, int):
        model: cls = cls.Primary(1)
        if model is None:
            model = cls.default_config()
        return model.CaseImage_W, model.CaseImage_H

    @classmethod
    def setVideoStream_W       (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.VideoStream_W       : int(value)})

    @classmethod
    def setVideoStream_H       (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.VideoStream_H       : int(value)})

    @classmethod
    def setPreviewImage_W      (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.PreviewImage_W      : int(value)})

    @classmethod
    def setPreviewImage_H      (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.PreviewImage_H      : int(value)})

    @classmethod
    def setMVideoStream_W      (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.MVideoStream_W      : int(value)})

    @classmethod
    def setMVideoStream_H      (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.MVideoStream_H      : int(value)})

    @classmethod
    def setMPreviewImage_W     (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.MPreviewImage_W     : int(value)})

    @classmethod
    def setMPreviewImage_H     (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.MPreviewImage_H     : int(value)})

    @classmethod
    def setSlideAreaImage_W    (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.SlideAreaImage_W    : int(value)})

    @classmethod
    def setSlideAreaImage_H    (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.SlideAreaImage_H    : int(value)})

    @classmethod
    def setImageList_W         (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.ImageList_W         : int(value)})

    @classmethod
    def setImageList_H         (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.ImageList_H         : int(value)})

    @classmethod
    def setDrawImage_W         (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.DrawImage_W         : int(value)})

    @classmethod
    def setDrawImage_H         (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.DrawImage_H         : int(value)})

    @classmethod
    def setCaseImage_W         (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.CaseImage_W         : int(value)})

    @classmethod
    def setCaseImage_H         (cls, value: (int, float)):
        if isinstance(value, (int, float)):
            cls.changed({cls.CaseImage_H         : int(value)})

    @classmethod
    def getVideoStream_W       (cls) -> int:
        item: cls = cls.first()
        return item.GetVideoStream_W

    @classmethod
    def getVideoStream_H       (cls) -> int:
        item: cls = cls.first()
        return item.GetVideoStream_H

    @classmethod
    def getPreviewImage_W      (cls) -> int:
        item: cls = cls.first()
        return item.GetPreviewImage_W

    @classmethod
    def getPreviewImage_H      (cls) -> int:
        item: cls = cls.first()
        return item.GetPreviewImage_H

    @classmethod
    def getMVideoStream_W      (cls) -> int:
        item: cls = cls.first()
        return item.GetMVideoStream_W

    @classmethod
    def getMVideoStream_H      (cls) -> int:
        item: cls = cls.first()
        return item.GetMVideoStream_H

    @classmethod
    def getMPreviewImage_W     (cls) -> int:
        item: cls = cls.first()
        return item.GetMPreviewImage_W

    @classmethod
    def getMPreviewImage_H     (cls) -> int:
        item: cls = cls.first()
        return item.GetMPreviewImage_H

    @classmethod
    def getSlideAreaImage_W    (cls) -> int:
        item: cls = cls.first()
        return item.GetSlideAreaImage_W

    @classmethod
    def getSlideAreaImage_H    (cls) -> int:
        item: cls = cls.first()
        return item.GetSlideAreaImage_H

    @classmethod
    def getImageList_W         (cls) -> int:
        item: cls = cls.first()
        return item.GetImageList_W

    @classmethod
    def getImageList_H         (cls) -> int:
        item: cls = cls.first()
        return item.GetImageList_H

    @classmethod
    def getDrawImage_W         (cls) -> int:
        item: cls = cls.first()
        return item.GetDrawImage_W

    @classmethod
    def getDrawImage_H         (cls) -> int:
        item: cls = cls.first()
        return item.GetDrawImage_H

    @classmethod
    def getCaseImage_W         (cls) -> int:
        item: cls = cls.first()
        return item.GetCaseImage_W

    @classmethod
    def getCaseImage_H         (cls) -> int:
        item: cls = cls.first()
        return item.GetCaseImage_H

    def SetVideoStream_W    (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.VideoStream_W    = int(value)

    def SetVideoStream_H    (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.VideoStream_H    = int(value)

    def SetPreviewImage_W   (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.PreviewImage_W   = int(value)

    def SetPreviewImage_H   (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.PreviewImage_H   = int(value)

    def SetMVideoStream_W   (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.MVideoStream_W   = int(value)

    def SetMVideoStream_H   (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.MVideoStream_H   = int(value)

    def SetMPreviewImage_W  (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.MPreviewImage_W  = int(value)

    def SetMPreviewImage_H  (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.MPreviewImage_H  = int(value)

    def SetSlideAreaImage_W (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.SlideAreaImage_W = int(value)

    def SetSlideAreaImage_H (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.SlideAreaImage_H = int(value)

    def SetImageList_W      (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.ImageList_W      = int(value)

    def SetImageList_H      (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.ImageList_H      = int(value)

    def SetDrawImage_W      (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.DrawImage_W      = int(value)

    def SetDrawImage_H      (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.DrawImage_H      = int(value)

    def SetCaseImage_W      (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.CaseImage_W      = int(value)

    def SetCaseImage_H      (self, value: (int, float)):
        if isinstance(value, (int, float)):
            self.CaseImage_H      = int(value)

    @property
    def GetVideoStream_W       (self) -> int:
        return 400    if not self.hasVideoStream_W    else self.VideoStream_W

    @property
    def GetVideoStream_H       (self) -> int:
        return 400    if not self.hasVideoStream_H    else self.VideoStream_H

    @property
    def GetPreviewImage_W      (self) -> int:
        return 800    if not self.hasPreviewImage_W   else self.PreviewImage_W

    @property
    def GetPreviewImage_H      (self) -> int:
        return 800    if not self.hasPreviewImage_H   else self.PreviewImage_H

    @property
    def GetMVideoStream_W      (self) -> int:
        return 400    if not self.hasMVideoStream_W   else self.MVideoStream_W

    @property
    def GetMVideoStream_H      (self) -> int:
        return 300    if not self.hasMVideoStream_H   else self.MVideoStream_H

    @property
    def GetMPreviewImage_W     (self) -> int:
        return 800    if not self.hasMPreviewImage_W  else self.MPreviewImage_W

    @property
    def GetMPreviewImage_H     (self) -> int:
        return 600    if not self.hasMPreviewImage_H  else self.MPreviewImage_H

    @property
    def GetSlideAreaImage_W    (self) -> int:
        return 7      if not self.hasSlideAreaImage_W else self.SlideAreaImage_W

    @property
    def GetSlideAreaImage_H    (self) -> int:
        return 11     if not self.hasSlideAreaImage_H else self.SlideAreaImage_H

    @property
    def GetImageList_W         (self) -> int:
        return 256    if not self.hasImageList_W      else self.ImageList_W

    @property
    def GetImageList_H         (self) -> int:
        return 256    if not self.hasImageList_H      else self.ImageList_H

    @property
    def GetDrawImage_W         (self) -> int:
        return 600    if not self.hasDrawImage_W      else self.DrawImage_W

    @property
    def GetDrawImage_H         (self) -> int:
        return 600    if not self.hasDrawImage_H      else self.DrawImage_H

    @property
    def GetCaseImage_W         (self) -> int:
        return 1024   if not self.hasCaseImage_W      else self.CaseImage_W

    @property
    def GetCaseImage_H         (self) -> int:
        return 1024   if not self.hasCaseImage_H      else self.CaseImage_H

    __field__ = (
           'ID'                 ,
           '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 ,
    )

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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