#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: RoleModel.py
 @DateTime: 2025/6/22 20:36
 @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, 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 RoleModel(CoreModel):
    __tablename__ = 't_RoleModel'
    ID          : Mapped[int                ] = mapped_column(primary_key=True                  , nullable=False)
    IS_ACTIVE   : Mapped[int                ] = mapped_column(default=1                         , nullable=True )
    ROLENAME    : Mapped[str                ] = mapped_column(Text    , default=''              , nullable=True )
    LAST_LOGIN  : Mapped[datetime           ] = mapped_column(DateTime, default=datetime.now()  , nullable=True )
    DATE_JOINED : Mapped[datetime           ] = mapped_column(DateTime, default=datetime.now()  , nullable=True )

    @classmethod
    def initModels(cls):
        return [
            cls.instance(ID=1, IS_ACTIVE=1,  LAST_LOGIN=datetime.now(), DATE_JOINED=datetime.now(), ROLENAME='默认管理员'),
            cls.instance(ID=2, IS_ACTIVE=1,  LAST_LOGIN=datetime.now(), DATE_JOINED=datetime.now(), ROLENAME='管理员'  ),
            cls.instance(ID=3, IS_ACTIVE=1,  LAST_LOGIN=datetime.now(), DATE_JOINED=datetime.now(), ROLENAME='用户'   ),
        ]
    def __init__(self, **args):
        super(RoleModel, self).__init__()
        self.initialize()
        self.initParameter(**args)

    __field__ = (
        'ID'           ,
        'IS_ACTIVE'    ,
        'ROLENAME'     ,
        'LAST_LOGIN'   ,
        'DATE_JOINED'  ,
    )
    __types__ = (
        int                ,
        int                ,
        str                ,
        datetime           ,
        datetime           ,
    )