# Path: invenio_communities/records/records/systemfields/communities/field.py
# class CommunitiesField(SystemField):
#     """Communites system field for managing relations to communities."""
# 
#     def __init__(self, m2m_model_cls, key='communities', context_cls=None,
#                  manager_cls=None):
#         self._m2m_model_cls = m2m_model_cls
#         self._context_cls = context_cls or CommunitiesFieldContext
#         self._manager_cls = manager_cls or CommunitiesRelationManager
#         super().__init__(key=key)
# 
#     #
#     # Life-cycle hooks
#     #
#     def pre_commit(self, record):
#         """Commit the communities field."""
#         manager = self.obj(record)
#         self.set_dictkey(record, manager.to_dict())
# 
#     #
#     # Helpers
#     #
#     def obj(self, record):
#         """Get or crate the communities manager."""
#         # Check cache
#         obj = self._get_cache(record)
#         if obj is not None:
#             return obj
# 
#         data = self.get_dictkey(record)
#         # Create manager
#         obj = self._manager_cls(self._m2m_model_cls, record.id, data)
#         self._set_cache(record, obj)
#         return obj
# 
#     # Data descriptor methods (i.e. attribute access)
#     # __set__() not defined on purpose
#     def __get__(self, record, owner=None):
#         """Get the persistent identifier."""
#         if record is None:
#             return self._context_cls(self, owner)
#         return self.obj(record)
# 
# Path: tests/records/mock_module/models.py
# class MockRecordMetadata(db.Model, RecordMetadataBase):
#     """A baisc record."""
# 
#     __tablename__ = 'mock_metadata'
# 
# class MockRecordCommunity(db.Model, CommunityRelationMixin):
#     """Relationship between record and community."""
# 
#     __tablename__ = 'mock_community'
#     __record_model__ = MockRecordMetadata
#     # __request_model__ = RequestMetadata


from invenio_records.systemfields import ConstantField
from invenio_records_resources.records import Record as RecordBase
from invenio_records_resources.records.systemfields import IndexField
from invenio_communities.records.records.systemfields import CommunitiesField
from .models import MockRecordMetadata, MockRecordCommunity
"""Example of a record draft API."""





class MockRecord(RecordBase):
    """Example parent record."""

    # Configuration
    model_cls = MockRecordMetadata

    # System fields
    schema = ConstantField('$schema', 'local://mocks/mock-v1.0.0.json')

    index = IndexField('mocks-mock-v1.0.0', search_alias='mocks')


# Path: invenio_communities/records/records/systemfields/communities/field.py
# class CommunitiesField(SystemField):
#     """Communites system field for managing relations to communities."""
# 
#     def __init__(self, m2m_model_cls, key='communities', context_cls=None,
#                  manager_cls=None):
#         self._m2m_model_cls = m2m_model_cls
#         self._context_cls = context_cls or CommunitiesFieldContext
#         self._manager_cls = manager_cls or CommunitiesRelationManager
#         super().__init__(key=key)
# 
#     #
#     # Life-cycle hooks
#     #
#     def pre_commit(self, record):
#         """Commit the communities field."""
#         manager = self.obj(record)
#         self.set_dictkey(record, manager.to_dict())
# 
#     #
#     # Helpers
#     #
#     def obj(self, record):
#         """Get or crate the communities manager."""
#         # Check cache
#         obj = self._get_cache(record)
#         if obj is not None:
#             return obj
# 
#         data = self.get_dictkey(record)
#         # Create manager
#         obj = self._manager_cls(self._m2m_model_cls, record.id, data)
#         self._set_cache(record, obj)
#         return obj
# 
#     # Data descriptor methods (i.e. attribute access)
#     # __set__() not defined on purpose
#     def __get__(self, record, owner=None):
#         """Get the persistent identifier."""
#         if record is None:
#             return self._context_cls(self, owner)
#         return self.obj(record)
# 
# Path: tests/records/mock_module/models.py
# class MockRecordMetadata(db.Model, RecordMetadataBase):
#     """A baisc record."""
# 
#     __tablename__ = 'mock_metadata'
# 
# class MockRecordCommunity(db.Model, CommunityRelationMixin):
#     """Relationship between record and community."""
# 
#     __tablename__ = 'mock_community'
#     __record_model__ = MockRecordMetadata
#     # __request_model__ = RequestMetadata


# Path: tests/records/mock_module/api.py
from invenio_records.systemfields import ConstantField
from invenio_records_resources.records import Record as RecordBase
from invenio_records_resources.records.systemfields import IndexField
from invenio_communities.records.records.systemfields import CommunitiesField
from .models import MockRecordMetadata, MockRecordCommunity

"""Example of a record draft API."""





class MockRecord(RecordBase):
    """Example parent record."""

    # Configuration
    model_cls = MockRecordMetadata

    # System fields
    schema = ConstantField('$schema', 'local://mocks/mock-v1.0.0.json')

    index = IndexField('mocks-mock-v1.0.0', search_alias='mocks')


    communities = CommunitiesField(MockRecordCommunity)