# Path: models/plugin_document.py
# class PluginDocument(object):
#     """Abstract class for all plugins to make their own document type."""
# 
#     def __init__(self):
#         super().__init__()
#         if self.__class__ is PluginDocument:
#             raise NotImplementedError
# 
#     id = Column(Integer(), primary_key=True)
#     @declared_attr
#     def owner(cls):
#         return Column(Integer(), ForeignKey('user.id'))
#     title = Column(String(256))
#     last_modified = Column(Integer())
#     description = Column(Text())
# 
# Path: database.py
# def get_session():
# def teardown_session(exception):


from .plugin_document import PluginDocument
from database import TableBase, Column, Integer, String, ForeignKey


class Document(TableBase):
    """An object refer to an actual plugin-managed document.

    Every actual document is not only saved in plugins' table, but also has an entry here, so that we can easily get all documents belong to a specific user."""

    __tablename__ = 'document'

    def __init__(self, plugin_name: str, doc: PluginDocument):
        super().__init__()
        self.owner = doc.owner
        self.plugin_name = plugin_name
        self.plugin_document_id = doc.id

    document_id = Column(Integer(), primary_key=True)

# Path: models/plugin_document.py
# class PluginDocument(object):
#     """Abstract class for all plugins to make their own document type."""
# 
#     def __init__(self):
#         super().__init__()
#         if self.__class__ is PluginDocument:
#             raise NotImplementedError
# 
#     id = Column(Integer(), primary_key=True)
#     @declared_attr
#     def owner(cls):
#         return Column(Integer(), ForeignKey('user.id'))
#     title = Column(String(256))
#     last_modified = Column(Integer())
#     description = Column(Text())
# 
# Path: database.py
# def get_session():
# def teardown_session(exception):


# Path: models/document.py
from .plugin_document import PluginDocument
from database import TableBase, Column, Integer, String, ForeignKey



class Document(TableBase):
    """An object refer to an actual plugin-managed document.

    Every actual document is not only saved in plugins' table, but also has an entry here, so that we can easily get all documents belong to a specific user."""

    __tablename__ = 'document'

    def __init__(self, plugin_name: str, doc: PluginDocument):
        super().__init__()
        self.owner = doc.owner
        self.plugin_name = plugin_name
        self.plugin_document_id = doc.id

    document_id = Column(Integer(), primary_key=True)

    owner = Column(Integer(), ForeignKey('user.id'))