#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：SlideScanningModel.py\n
 @DateTime: 2025/6/23 14:15\n
 @Author  ：xsh
"""

from PyQt5 import Qt
from datetime import datetime
from sqlalchemy.orm import (Mapped, mapped_column)
from sqlalchemy.types import (Text, DateTime)
from AppCore        .Levels import *
from AppSettings    .utils import *
from AppCore.AppDBModels.SlideModels.SlideModelInterface import SlideModelInterface

class SlideScanningModel(SlideModelInterface):
    __tablename__ = 't_SlideScanningModel'
    ID                  : Mapped[int            ] = mapped_column(primary_key=True                                      , nullable=False , doc='数据ＩＤ　　', comment='数据ＩＤ　　') # '数据ＩＤ　　'
    Level               : Mapped[int            ] = mapped_column(            default=ScanStatusLevel.Default_Status    , nullable=True  , doc='当前状态　　', comment='当前状态　　') # '当前状态　　'
    ObjectiveLevel      : Mapped[int            ] = mapped_column(            default=ObjectiveLevel.ObjectiveNone      , nullable=True  , doc='物镜类型　　', comment='物镜类型　　') # '物镜类型　　'
    ChamberGroupNumber  : Mapped[int            ] = mapped_column(            default=1                                 , nullable=True  , doc='片仓组号　　', comment='片仓组号　　') # '片仓组号　　'
    ChamberRowNumber    : Mapped[int            ] = mapped_column(            default=1                                 , nullable=True  , doc='片仓行号　　', comment='片仓行号　　') # '片仓行号　　'
    TrayNumber          : Mapped[int            ] = mapped_column(            default=ModuleLevel.ModuleTraySlide1      , nullable=True  , doc='托盘编号　　', comment='托盘编号　　') # '托盘编号　　'
    LState              : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='左边状态　　', comment='左边状态　　') # '左边状态　　'
    RState              : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='右边状态　　', comment='右边状态　　') # '右边状态　　'
    RowNumber           : Mapped[int            ] = mapped_column(            default=1                                 , nullable=True  , doc='图片行号　　', comment='图片行号　　') # '图片行号　　'
    ColNumber           : Mapped[int            ] = mapped_column(            default=1                                 , nullable=True  , doc='图片列号　　', comment='图片列号　　') # '图片列号　　'
    ImageScore          : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='图片评分　　', comment='图片评分　　') # '图片评分　　'
    IsSave              : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='是否保存　　', comment='是否保存　　') # '是否保存　　'
    ImageCellX          : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='小图中心Ｘ　', comment='小图中心Ｘ　') # '小图中心Ｘ　'
    ImageCellY          : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='小图中心Ｙ　', comment='小图中心Ｙ　') # '小图中心Ｙ　'
    ImageCellWidth      : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='小图宽度　　', comment='小图宽度　　') # '小图宽度　　'
    ImageCellHeight     : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='小图高度　　', comment='小图高度　　') # '小图高度　　'
    ImageCellScore      : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='小图评分　　', comment='小图评分　　') # '小图评分　　'
    ImageCellType       : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='小图类型　　', comment='小图类型　　') # '小图类型　　'
    ScanTemplateID      : Mapped[int            ] = mapped_column(            default=1                                 , nullable=True  , doc='模板ＩＤ　　', comment='模板ＩＤ　　') # '模板ＩＤ　　'
    Index               : Mapped[int            ] = mapped_column(            default=0                                 , nullable=True  , doc='数据序号　　', comment='数据序号　　') # '数据序号　　'
    Position_X          : Mapped[float          ] = mapped_column(            default=0.0                               , nullable=True  , doc='托盘位置Ｘ　', comment='托盘位置Ｘ　') # '托盘位置Ｘ　'
    Position_Y          : Mapped[float          ] = mapped_column(            default=0.0                               , nullable=True  , doc='托盘位置Ｙ　', comment='托盘位置Ｙ　') # '托盘位置Ｙ　'
    Position_Z          : Mapped[float          ] = mapped_column(            default=0.0                               , nullable=True  , doc='托盘位置Ｚ　', comment='托盘位置Ｚ　') # '托盘位置Ｚ　'
    CodeString          : Mapped[str            ] = mapped_column(Text      , default=''                                , nullable=True  , doc='二维码编号　', comment='二维码编号　') # '二维码编号　'
    SpecimenNumber      : Mapped[str            ] = mapped_column(Text      , default=''                                , nullable=True  , doc='样本编号　　', comment='样本编号　　') # '样本编号　　'
    SlideNumber         : Mapped[str            ] = mapped_column(Text      , default=''                                , nullable=True  , doc='玻片编号　　', comment='玻片编号　　') # '玻片编号　　'
    LineNumber          : Mapped[str            ] = mapped_column(Text      , default=''                                , nullable=True  , doc='样本线号　　', comment='样本线号　　') # '样本线号　　'
    SavePath            : Mapped[str            ] = mapped_column(Text      , default=''                                , nullable=True  , doc='保存路径　　', comment='保存路径　　') # '保存路径　　'
    CreateTime          : Mapped[datetime       ] = mapped_column(DateTime  , default=datetime.now()                    , nullable=True  , doc='创建时间　　', comment='创建时间　　') # '创建时间　　'
    def __init__(self, **args):
        super(SlideScanningModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    __field__ = (
        'ID'                 ,
        'Level'              ,
        'ObjectiveLevel'     ,
        'ChamberGroupNumber' ,
        'ChamberRowNumber'   ,
        'TrayNumber'         ,
        'LState'             ,
        'RState'             ,
        'RowNumber'          ,
        'ColNumber'          ,
        'ImageScore'         ,
        'IsSave'             ,
        'ImageCellX'         ,
        'ImageCellY'         ,
        'ImageCellWidth'     ,
        'ImageCellHeight'    ,
        'ImageCellScore'     ,
        'ImageCellType'      ,
        'ScanTemplateID'     ,
        'Index'              ,
        'Position_X'         ,
        'Position_Y'         ,
        'Position_Z'         ,
        'CodeString'         ,
        'SpecimenNumber'     ,
        'SlideNumber'        ,
        'LineNumber'         ,
        'SavePath'           ,
        'CreateTime'         ,
    )
    __types__ = (
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        int            ,
        float          ,
        float          ,
        float          ,
        str            ,
        str            ,
        str            ,
        str            ,
        str            ,
        datetime       ,
    )
    # @classmethod
    # def initModels(cls):
    #     from AppCore.AppDBModels.TrayModels.TrayModel import TrayModel
    #     tray1: TrayModel = TrayModel.getTrayModel(ModuleLevel.ModuleTraySlide1)
    #     tray2: TrayModel = TrayModel.getTrayModel(ModuleLevel.ModuleTraySlide2)
    #     MinRowNumber        : int
    #     MaxRowNumber        : int
    #     MinColNumber        : int
    #     MaxColNumber        : int
    #     RowNumber           : int
    #     ColNumber           : int
    #     ChamberNumber       : int
    #     MinChamberNumber    : int
    #     MaxChamberNumber    : int
    #     item                : cls
    #     Index               : int = 1
    #     items               : list[cls] = []
    #     MinRowNumber, MaxRowNumber = tray1.getRowNumberRange()
    #     MinColNumber, MaxColNumber = tray1.getColNumberRange()
    #     for RowNumber in range(MinRowNumber, MaxRowNumber + 1):
    #         for ColNumber in range(MinColNumber, MaxColNumber + 1):
    #             item = cls.instance(ID=Index, RowNumber=RowNumber, ColNumber=ColNumber)
    #             item.RowNumber = RowNumber
    #             item.ColNumber = ColNumber
    #             cls.setModelPosition(tray1, item, 1, 1, ObjectiveLevel.ObjectiveNone, '')
    #             items.append(item)
    #             Index += 1
    #     MinRowNumber, MaxRowNumber = tray2.getRowNumberRange()
    #     MinColNumber, MaxColNumber = tray2.getColNumberRange()
    #     for RowNumber in range(MinRowNumber, MaxRowNumber + 1):
    #         for ColNumber in range(MinColNumber, MaxColNumber + 1):
    #             item = cls.instance(ID=Index, RowNumber=RowNumber, ColNumber=ColNumber)
    #             item.RowNumber = RowNumber
    #             item.ColNumber = ColNumber
    #             cls.setModelPosition(tray2, item, 1, 1, ObjectiveLevel.ObjectiveNone, '')
    #             items.append(item)
    #             Index += 1
    #     return items