#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: AppInterface.py
 @DateTime: 2025/4/7 22:15
 @SoftWare: PyCharm
 @Author  ：xsh
"""
from PyQt5 import Qt
import types
from AppUtils.AppConvert import AppConvert

class AppInterface:
    Name        : str
    Information : str
    @staticmethod
    def has__dict__(buffer) -> bool:
        return hasattr(buffer, '__dict__')
    def set_method(self, key: str, value):
        setattr(self, key, types.MethodType(value, self))

    def get_method(self, key: str):
        return getattr(self, key, None)

    def get_property(self, key: str, dst_type: type):
        value = getattr(self, key, None)
        return AppConvert.ObjectConvert(value, dst_type)

    def set_property(self, key: str, value: object):
        setattr(self, key, value)

    def initialization(self, info: str):
        self.Name = f"{self.__class__.__name__}"
        self.Information = info
        self.initialize()

    def has_field(self, key: str, TYPE: type) -> bool:
        return hasattr(self, key) and (isinstance(getattr(self, key, None), TYPE) or getattr(self, key, None) is not None)

    def isEqual(self, other) -> bool:
        return True if other is not None and id(self) == id(other) else False

    def __eq__(self, other):
        return self.isEqual(other)
    def __ne__(self, other):
        return not self.isEqual(other)

    def initialize(self):
        self.initData       ()
        self.initValue      ()
        self.initProperty   ()
        self.initConnect    ()

    def deinitialize(self):
        self.deleConnect    ()
        self.deleProperty   ()
        self.deleValue      ()
        self.deleData       ()

    def initData(self):
        pass

    def deleData(self):
        pass

    def initConnect(self):
        pass

    def deleConnect(self):
        pass

    def initValue(self):
        pass

    def deleValue(self):
        pass

    def initProperty(self):
        pass

    def deleProperty(self):
        pass

    def __getattr__(self, item):
        return self.__dict__.get(f"{item}", None)

    def __setattr__(self, item, value):
        self.__dict__[f"{item}"] = value



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

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

    def hasAttribute(self, name: str, TYPE: type) -> bool:
        if TYPE is None:
            return False
        return hasattr(self, name) and isinstance(getattr(self, name, None), TYPE)

class AppModelInterface:
    @staticmethod
    def has__dict__(buffer) -> bool:
        return hasattr(buffer, '__dict__')
    def __getattr__(self, item):
        return self.__dict__.get(f"{item}", None)

    def __setattr__(self, item, value):
        self.__dict__[f"{item}"] = value

    def get_property(self, key: str, dst_type: type):
        value = self.__dict__.get(key, None)
        return AppConvert.ObjectConvert(value, dst_type)

    def set_property(self, key: str, value: object):
        self.__dict__[key] = value

    def isEqual(self, other) -> bool:
        if not isinstance(other, AppModelInterface):
            return False
        if id(self) == id(other):
            return True
        for key, value in self.__dict__.items():
            if getattr(other, key, None) != value:
                return False
        return True

    def initialize(self):
        self.initData       ()
        self.initValue      ()
        self.initProperty   ()

    def deinitialize(self):
        self.deleProperty   ()
        self.deleValue      ()
        self.deleData       ()

    def initData(self):
        pass

    def deleData(self):
        pass

    def initValue(self):
        pass

    def deleValue(self):
        pass

    def initProperty(self):
        pass

    def deleProperty(self):
        pass