#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：AnointingModel.py\n
 @DateTime: 2025/7/10 9:10\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 AnointingModel(CoreModel):
    __tablename__ = 't_AnointingModel'
    Level                           : Mapped[int    ] = mapped_column(primary_key=True      , nullable=False, doc='物镜类型　　　　')
    OilDropingNumber                : Mapped[int    ] = mapped_column(default=2             , nullable=True , doc='滴油位置数量　　')
    AnointingNumber                 : Mapped[int    ] = mapped_column(default=4             , nullable=True , doc='抹油位置数量　　')
    OilDropingTimes                 : Mapped[int    ] = mapped_column(default=1000          , nullable=True , doc='滴油时间　　　　')
    OilDropingFinishWaitTimes       : Mapped[int    ] = mapped_column(default=3000          , nullable=True , doc='滴油完成等待时间')
    OilDropingSpeed                 : Mapped[int    ] = mapped_column(default=100           , nullable=True , doc='滴油油泵速度　　')
    AnointingTimes                  : Mapped[int    ] = mapped_column(default=1000          , nullable=True , doc='抹油等待时间　　')
    AnointingCount                  : Mapped[int    ] = mapped_column(default=2             , nullable=True , doc='抹油运动次数　　')
    OffsetRowNumber                 : Mapped[int    ] = mapped_column(default=15            , nullable=True , doc='滴油偏移行数　　')
    OffsetColNumber                 : Mapped[int    ] = mapped_column(default=0             , nullable=True , doc='滴油偏移行数　　')
    OilDaub_Position                : Mapped[int    ] = mapped_column(default=4000000       , nullable=True , doc='抹油或滴油高度　')
    ClearOil_Position               : Mapped[int    ] = mapped_column(default=4000000       , nullable=True , doc='清除剩余镜油高度')
    def __init__(self, **args):
        super(AnointingModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    __header__ = (
        '物镜类型　　　　',
        '滴油位置数量　　',
        '抹油位置数量　　',
        '滴油时间　　　　',
        '滴油完成等待时间',
        '滴油油泵速度　　',
        '抹油等待时间　　',
        '抹油运动次数　　',
        '滴油偏移行数　　',
        '滴油偏移行数　　',
        '抹油或滴油高度　',
        '清除剩余镜油高度',
    )
    @classmethod
    def default_config(cls, **args):
        result: cls = cls.__new__(cls)
        result.__init__(**args)
        result.init_default()
        return result

    def initValue(self):
        super(AnointingModel, self).initValue()
        self.Level                           = ObjectiveLevel.ObjectiveNone     #
        self.OilDropingNumber                = 2                                #
        self.AnointingNumber                 = 4                                #
        self.OilDropingTimes                 = 1000                             #
        self.OilDropingFinishWaitTimes       = 3000                             #
        self.OilDropingSpeed                 = 100                              #
        self.AnointingTimes                  = 1000                             #
        self.AnointingCount                  = 2                                #
        self.OffsetRowNumber                 = 15                               #
        self.OffsetColNumber                 = 0                                #
        self.OilDaub_Position                = 5400000                          #
        self.ClearOil_Position               = 5400000
    @classmethod
    def initModels(cls) -> list:
        return [
            cls.instance(Level=ObjectiveLevel.Objective1    ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
            cls.instance(Level=ObjectiveLevel.Objective10   ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
            cls.instance(Level=ObjectiveLevel.Objective40   ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
            cls.instance(Level=ObjectiveLevel.Objective20   ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
            cls.instance(Level=ObjectiveLevel.Objective63   ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
            cls.instance(Level=ObjectiveLevel.Objective100  ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
            cls.instance(Level=ObjectiveLevel.ObjectiveNone ,  OilDropingNumber                = 2       ,AnointingNumber                 = 4       ,OilDropingTimes                 = 1000    ,OilDropingFinishWaitTimes       = 3000    ,OilDropingSpeed                 = 100     ,AnointingTimes                  = 1000    ,AnointingCount                  = 2       ,OffsetRowNumber                 = 15      ,OffsetColNumber                 = 0       ,OilDaub_Position = 4000000 , ClearOil_Position=4000000),
        ]

    @classmethod
    def getConfig(cls, level: int):
        Level: int = level if level in ObjectiveLevel.all() else ObjectiveLevel.ObjectiveNone
        item: cls = cls.Primary(Level)
        if item is None:
            item = cls.instance()
            item.initValue()
        return item

    __field__ = (
        'Level'                     ,
        'OilDropingNumber'          ,
        'AnointingNumber'           ,
        'OilDropingTimes'           ,
        'OilDropingFinishWaitTimes' ,
        'OilDropingSpeed'           ,
        'AnointingTimes'            ,
        'AnointingCount'            ,
        'OffsetRowNumber'           ,
        'OffsetColNumber'           ,
        'OilDaub_Position'          ,
        'ClearOil_Position'         ,
    )
    __types__ = (
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
        int    ,
    )