#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: DBContext.py
 @DateTime: 2025/4/8 20:31
 @SoftWare: PyCharm
 @Author  ：xsh
"""
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *


class DBContext(ContextModelInterface):
    __slots__ = (
        'DBHost'    ,
        'DBName'    ,
        'DBUser'    ,
        'DBPass'    ,
        'DBLevel'   ,
        'DBPort'    ,
        'IsOpen'    ,
    )
    __types__ = (
        str  ,
        str  ,
        str  ,
        str  ,
        str  ,
        int  ,
        bool ,
    )
    DBHost   : str
    DBName   : str
    DBUser   : str
    DBPass   : str
    DBLevel  : str
    DBPort   : int
    IsOpen   : bool
    def __init__(self, *args, **kwargs):
        super(DBContext, self).__init__(*args, **kwargs)
        self.initialization("数据库上下文")

    def initParameter(self, **args):
        super(DBContext, self).initParameter(**args)
        if not isinstance(args, dict) or len(args) <= 0:
            return
        for index, _property in enumerate(self.__slots__):
            setattr(self, _property, AppConvert.ObjectConvert(args.get(_property, getattr(self, _property, None)),
                                                              self.__types__[index]))

    def initValue(self):
        super(DBContext, self).initValue()
        self.DBHost    = "127.0.0.1"
        self.DBName    = "zeiss_microscope_scan"
        self.DBUser    = "root"
        self.DBPass    = "Rain100903"
        self.DBLevel   = "DBConnectOptions_DEFAULT"
        self.DBPort    = 3306
        self.IsOpen    = False

    def get_sqlalchemy_info(self) -> str:
        return f'mysql+mysqlconnector://{self.DBUser}:{self.DBPass}@{self.DBHost}:{self.DBPort}/{self.DBName}?charset=utf8'

    def get_sqlalchemy_information(self) -> str:
        return f'mysql+pymysql://{self.DBUser}:{self.DBPass}@{self.DBHost}:{self.DBPort}/{self.DBName}?charset=utf8'
