# Copyright (c) 2025, JINGROW and contributors
# For license information, please see license.txt

"""
Jingrow Local 元数据模型
与 SaaS 版完全一致的 Meta 实现
"""

from typing import Dict, List, Any, Optional, Union

class Meta:
    """元数据基类 - 与 SaaS 版完全一致"""
    
    def __init__(self, doctype: str = None, **kwargs):
        self.doctype = doctype
        self._data = kwargs.copy()
    
    def __getattr__(self, name):
        """动态获取属性"""
        if name.startswith('_'):
            raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
        return self._data.get(name)
    
    def __setattr__(self, name, value):
        """动态设置属性"""
        if name.startswith('_') or name == 'doctype':
            super().__setattr__(name, value)
        else:
            if not hasattr(self, '_data'):
                super().__setattr__(name, value)
            else:
                self._data[name] = value
    
    def as_dict(self):
        """转换为字典"""
        result = self._data.copy()
        result['doctype'] = self.doctype
        return result
