#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: Collectsettings.py
 @DateTime: 2025/6/22 15:25
 @SoftWare: PyCharm
 @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
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 Collectsettings(CoreModel):
    __tablename__   = 't_collectsettings'
    ID              : Mapped[int ] = mapped_column   (primary_key=True                                  , nullable=False, doc='数据序号　', comment='数据序号　') # 数据序号
    objective_level : Mapped[int ] = mapped_column   (default=6                                         , nullable=True , doc='物镜类型　', comment='物镜类型　') # 物镜类型
    classifier      : Mapped[str ] = mapped_column   (Text, default='Karyotyping'                       , nullable=True , doc='分类模型　', comment='分类模型　') # 分类模型
    cell_count      : Mapped[int ] = mapped_column   (default=100                                       , nullable=True , doc='细胞数量　', comment='细胞数量　') # 细胞数量
    scanning_order  : Mapped[int ] = mapped_column   (default=0                                         , nullable=True , doc='扫描方式　', comment='扫描方式　') # 扫描方式
    is_save         : Mapped[int ] = mapped_column   (default=1                                         , nullable=True , doc='是否保存　', comment='是否保存　') # 是否保存
    image_format    : Mapped[str ] = mapped_column   (Text, default='jpg'                               , nullable=True , doc='数据格式　', comment='数据格式　') # 数据格式
    save_address    : Mapped[str ] = mapped_column   (Text, default='d:\\DeepLearning_data\\'           , nullable=True , doc='保存路径　', comment='保存路径　') # 保存路径
    __header__ = (
        '数据序号　',
        '物镜类型　',
        '分类模型　',
        '细胞数量　',
        '扫描方式　',
        '是否保存　',
        '数据格式　',
        '保存路径　',
    )
    def __init__(self, **args):
        super(Collectsettings, self).__init__()
        self.initialize()
        self.initParameter(**args)

    def initValue(self):
        super(Collectsettings, self).initValue()
        self.ID               = None
        self.objective_level  = ObjectiveLevel.Objective100
        self.classifier       = 'Aberration'
        self.cell_count       = 100
        self.scanning_order   = 0
        self.is_save          = 1
        self.image_format     = 'jpg'
        self.save_address     = 'D:\\DeepLearning_data\\'

    def isAberration(self) -> bool:
        return False if not self.has_classifier else self.classifier == 'Aberration'

    def isMicronucleus(self) -> bool:
        return False if not self.has_classifier else self.classifier == 'Micronucleus'

    def isKaryotyping(self) -> bool:
        return False if not self.has_classifier else self.classifier == 'Karyotyping'
    @classmethod
    def initModels(cls):
        return [
            cls.instance(ID               = 1                             ,objective_level  = ObjectiveLevel.Objective100      ,classifier       = 'Aberration'                     ,cell_count       = 100                              ,scanning_order   = 0                                ,is_save          = 1                                ,image_format     = 'jpg'                            ,save_address     = 'D:\\DeepLearning_data\\' ),
            cls.instance(ID               = 2                             ,objective_level  = ObjectiveLevel.Objective40       ,classifier       = 'Micronucleus'                   ,cell_count       = 100                              ,scanning_order   = 0                                ,is_save          = 1                                ,image_format     = 'jpg'                            ,save_address     = 'D:\\DeepLearning_data\\' ),
            cls.instance(ID               = 3                             ,objective_level  = ObjectiveLevel.Objective100      ,classifier       = 'Karyotyping'                    ,cell_count       = 100                              ,scanning_order   = 0                                ,is_save          = 1                                ,image_format     = 'jpg'                            ,save_address     = 'D:\\DeepLearning_data\\' ),
        ]
    @property
    def has_ID              (self) -> bool:
        return hasattr(self, 'ID'                ) and isinstance(self.ID              , int )

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

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

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

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

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

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

    @property
    def has_save_address    (self) -> bool:
        return hasattr(self, 'save_address'      ) and isinstance(self.save_address    , str )
    __field__ = (
        'ID'                ,
        'objective_level'   ,
        'classifier'        ,
        'cell_count'        ,
        'scanning_order'    ,
        'is_save'           ,
        'image_format'      ,
        'save_address'      ,
    )
    __types__ = (
        int ,
        int ,
        str ,
        int ,
        int ,
        int ,
        str ,
        str ,
    )