#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
@FileName   : IntegrationExposureTimes.py
@Account    : Administrator
@Time       : 2025/8/29 16:56
@Author     : xsh
@Description: 
"""
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 IntegrationExposureTimes(CoreModel):
    __tablename__ = 't_IntegrationExposureTimes'
    ID          : Mapped[int    ] = mapped_column(primary_key=True  , nullable=False, doc='数据序号', comment='数据序号')
    ParentID    : Mapped[int    ] = mapped_column(default=1         , nullable=True , doc='模型序号', comment='模型序号')
    ExposureTime: Mapped[int    ] = mapped_column(default=2500      , nullable=True , doc='曝光时间', comment='曝光时间')
    HDRTime     : Mapped[float  ] = mapped_column(default=0.5       , nullable=True , doc='曝光时间', comment='曝光时间')
    def __init__(self, **args):
        super(IntegrationExposureTimes, self).__init__()
        self.initialize()
        self.initParameter(**args)

    @classmethod
    def initModels(cls):
        return [
            cls.instance(ID=1, ExposureTime=2500, ParentID=1, HDRTime=0.5),
            cls.instance(ID=2, ExposureTime=3000, ParentID=1, HDRTime=0.5),
            cls.instance(ID=3, ExposureTime=3500, ParentID=1, HDRTime=0.5),
            cls.instance(ID=4, ExposureTime=2500, ParentID=3, HDRTime=0.5),
            cls.instance(ID=5, ExposureTime=3000, ParentID=3, HDRTime=0.5),
            cls.instance(ID=6, ExposureTime=3500, ParentID=3, HDRTime=0.5),
        ]



    __field__ = (
        'ID'            ,
        'ParentID'      ,
        'ExposureTime'  ,
        'HDRTime'       ,
    )
    __types__ = (
        int     ,
        int     ,
        int     ,
        float   ,
    )

    @classmethod
    def ExposureTimes(cls) -> list[int]:
        items: list[cls] = cls.all()
        item: cls
        if not isinstance(items, list) or len(items) <= 0:
            return []
        return [item.ExposureTime for item in items if isinstance(item.ExposureTime, (int, float))]

    @classmethod
    def ClassifierExposureTimes(cls, parent_id: int) -> list[int]:
        items: list[cls] = cls.filter(cls.ParentID == parent_id)
        item: cls
        if not isinstance(items, list) or len(items) <= 0:
            return []
        return [item.ExposureTime for item in items if isinstance(item.ExposureTime, (int, float))]

    @classmethod
    def ClassifierHDRTimes(cls, parent_id: int) -> list[int]:
        items: list[cls] = cls.filter(cls.ParentID == parent_id)
        item: cls
        if not isinstance(items, list) or len(items) <= 0:
            return []
        return [item.HDRTime for item in items if isinstance(item.HDRTime, (int, float))]

    @classmethod
    def getConfig(cls, level: int):
        item: cls = cls.get(cls.ID == level)
        return item