# Path: invenio_communities/communities/records/api.py
# class Community(Record):
#     """Community API."""
# 
#     pid = PIDField('id', provider=CommunitiesIdProvider, create=False)
#     schema = ConstantField(
#         '$schema', 'local://communities/communities-v1.0.0.json')
# 
#     model_cls = models.CommunityMetadata
# 
#     index = IndexField(
#         "communities-communities-v1.0.0",
#         search_alias="communities"
#     )
# 
#     access = CommunityAccessField()
# 
#     bucket_id = ModelField(dump=False)
#     bucket = ModelField(dump=False)
#     files = FilesField(
#         store=False,
#         file_cls=CommunityFile,
#         # Don't delete, we'll manage in the service
#         delete=False,
#     )
# 
# Path: invenio_communities/communities/services/permissions.py
# class IfRestrictedBase(Generator):
# class IfRestricted(IfRestrictedBase):
# class IfPolicyClosed(IfRestrictedBase):
# class CommunityOwners(Generator):
# class CommunityPermissionPolicy(BasePermissionPolicy):
#     def __init__(self, field_getter,
#                  field_name, then_value, else_value, then_, else_):
#     def generators(self, record):
#     def needs(self, record=None, **kwargs):
#     def excludes(self, record=None, **kwargs):
#     def make_query(self, generators, **kwargs):
#     def query_filter(self, **kwargs):
#     def __init__(self, field, then_, else_):
#     def __init__(self, field, then_, else_):
#     def needs(self, record=None, **kwargs):
#     def query_filter(self, identity=None, **kwargs):


from invenio_records_resources.references.resolvers.records import \
    RecordPKProxy, RecordResolver
from .records.api import Community
from .services.permissions import CommunityNeed



class CommunityPKProxy(RecordPKProxy):
    """Resolver proxy for a Record entity using the UUID."""

    def get_need(self):
        """Return the user need of the community's owner."""
        # TODO this may become difficult once there's multiple levels
        #      of membership (owner, manager, curator, ...)
        #      -> which needs should be generated? None, and let the
        #         user create the set of required needs from the
        #         resolved entity? or keep the 'owner' need?
        comid = str(self._parse_ref_dict_id(self._ref_dict))
        return CommunityNeed(comid)


class CommunityResolver(RecordResolver):
    """Community entity resolver.

    The entity resolver enables Invenio-Requests to understand communities as
    receiver and topic of a request.
    """

    type_id = 'community'
    """Type identifier for this resolver."""

    def __init__(self):
        """Initialize the default record resolver."""
        super().__init__(

# Path: invenio_communities/communities/records/api.py
# class Community(Record):
#     """Community API."""
# 
#     pid = PIDField('id', provider=CommunitiesIdProvider, create=False)
#     schema = ConstantField(
#         '$schema', 'local://communities/communities-v1.0.0.json')
# 
#     model_cls = models.CommunityMetadata
# 
#     index = IndexField(
#         "communities-communities-v1.0.0",
#         search_alias="communities"
#     )
# 
#     access = CommunityAccessField()
# 
#     bucket_id = ModelField(dump=False)
#     bucket = ModelField(dump=False)
#     files = FilesField(
#         store=False,
#         file_cls=CommunityFile,
#         # Don't delete, we'll manage in the service
#         delete=False,
#     )
# 
# Path: invenio_communities/communities/services/permissions.py
# class IfRestrictedBase(Generator):
# class IfRestricted(IfRestrictedBase):
# class IfPolicyClosed(IfRestrictedBase):
# class CommunityOwners(Generator):
# class CommunityPermissionPolicy(BasePermissionPolicy):
#     def __init__(self, field_getter,
#                  field_name, then_value, else_value, then_, else_):
#     def generators(self, record):
#     def needs(self, record=None, **kwargs):
#     def excludes(self, record=None, **kwargs):
#     def make_query(self, generators, **kwargs):
#     def query_filter(self, **kwargs):
#     def __init__(self, field, then_, else_):
#     def __init__(self, field, then_, else_):
#     def needs(self, record=None, **kwargs):
#     def query_filter(self, identity=None, **kwargs):


# Path: invenio_communities/communities/resolver.py
from invenio_records_resources.references.resolvers.records import \
    RecordPKProxy, RecordResolver
from .records.api import Community
from .services.permissions import CommunityNeed




class CommunityPKProxy(RecordPKProxy):
    """Resolver proxy for a Record entity using the UUID."""

    def get_need(self):
        """Return the user need of the community's owner."""
        # TODO this may become difficult once there's multiple levels
        #      of membership (owner, manager, curator, ...)
        #      -> which needs should be generated? None, and let the
        #         user create the set of required needs from the
        #         resolved entity? or keep the 'owner' need?
        comid = str(self._parse_ref_dict_id(self._ref_dict))
        return CommunityNeed(comid)


class CommunityResolver(RecordResolver):
    """Community entity resolver.

    The entity resolver enables Invenio-Requests to understand communities as
    receiver and topic of a request.
    """

    type_id = 'community'
    """Type identifier for this resolver."""

    def __init__(self):
        """Initialize the default record resolver."""
        super().__init__(

            Community, type_key=self.type_id, proxy_cls=CommunityPKProxy)