# Path: hyperadmin/endpoints.py
# class Endpoint(GlobalSiteMixin, EndpointViewMixin, BaseEndpoint):
#     """
#     Endpoint class that contains link prototypes and maps HTTP requests to those links.
#     """
#     url_suffix = None
#     base_url_name_suffix = ''
# 
#     prototype_method_map = {}
# 
#     def get_available_methods(self):
#         return self.prototype_method_map.keys()
# 
#     def get_link_prototype_for_method(self, method):
#         """
#         Return the link prototype representing the action for the method
#         Consults prototype_method_map for the link name and returns the prototype from link_prototypes
#         """
#         name = self.prototype_method_map.get(method)
#         return self.link_prototypes.get(name)
# 
#     def get_link_kwargs(self, **kwargs):
#         kwargs.setdefault('endpoint', self)
#         if 'item' not in kwargs and self.state.item:
#             kwargs['item'] = self.state.item
#         return kwargs
# 
#     def get_available_links(self):
#         """
#         Returns a dictionary mapping available HTTP methods to a link
#         """
#         methods = dict()
#         for method in self.get_available_methods():
#             proto = self.get_link_prototype_for_method(method)
#             if proto and proto.show_link():
#                 kwargs = {'use_request_url':True}
#                 kwargs = self.get_link_kwargs(**kwargs)
#                 link = proto.get_link(**kwargs)
#                 methods[method] = link
#         return methods
# 
#     def get_url_suffix(self):
#         return self.url_suffix
# 
#     def get_view_kwargs(self, **kwargs):
#         """
#         :rtype: dict
#         """
#         params = dict(self._init_kwargs)
#         params.update(kwargs)
#         return params
# 
#     def get_view(self, **kwargs):
#         """
#         :rtype: view callable
#         """
#         #TODO should this be get_endpoint_kwargs?
#         params = self.get_view_kwargs(**kwargs)
#         view = type(self).as_view(**params)
#         #allow for retreiving the endpoint from url patterns
#         view.endpoint = self
#         #thus allowing us to do: myview.endpoint.get_view(**some_new_kwargs)
#         return view
# 
#     def get_url_object(self):
#         view = self.get_view()
#         return url(self.get_url_suffix(), view, name=self.get_url_name(),)
# 
#     def get_main_link_name(self):
#         return self.get_link_prototype_for_method('GET').name
# 
# Path: hyperadmin/links.py
# class LinkCollection(list):
#     def __init__(self, endpoint):
#         self.endpoint = endpoint
#     
#     @property
#     def link_prototypes(self):
#         return self.endpoint.link_prototypes
#     
#     def add_link(self, link_name, **kwargs):
#         """
#         Adds the specified link from the resource.
#         This will only add the link if it exists and the person is allowed to view it.
#         """
#         from hyperadmin.endpoints import BaseEndpoint
#         if isinstance(link_name, BaseEndpoint):
#             try:
#                 link_name = link_name.get_main_link_name()
#             except LinkNotAvailable:
#                 return False
#         if link_name not in self.link_prototypes:
#             return False
#         endpoint_link = self.link_prototypes[link_name]
#         if not endpoint_link.show_link(**kwargs):
#             return False
#         link = endpoint_link.get_link(**kwargs)
#         self.append(link)
#         return link


from hyperadmin.endpoints import Endpoint
from hyperadmin.links import LinkCollection


class ResourceEndpoint(Endpoint):
    @property
    def resource(self):
        return self.parent

    def create_link_collection(self):
        return LinkCollection(endpoint=self.resource)

    def get_resource_item(self, instance, **kwargs):

# Path: hyperadmin/endpoints.py
# class Endpoint(GlobalSiteMixin, EndpointViewMixin, BaseEndpoint):
#     """
#     Endpoint class that contains link prototypes and maps HTTP requests to those links.
#     """
#     url_suffix = None
#     base_url_name_suffix = ''
# 
#     prototype_method_map = {}
# 
#     def get_available_methods(self):
#         return self.prototype_method_map.keys()
# 
#     def get_link_prototype_for_method(self, method):
#         """
#         Return the link prototype representing the action for the method
#         Consults prototype_method_map for the link name and returns the prototype from link_prototypes
#         """
#         name = self.prototype_method_map.get(method)
#         return self.link_prototypes.get(name)
# 
#     def get_link_kwargs(self, **kwargs):
#         kwargs.setdefault('endpoint', self)
#         if 'item' not in kwargs and self.state.item:
#             kwargs['item'] = self.state.item
#         return kwargs
# 
#     def get_available_links(self):
#         """
#         Returns a dictionary mapping available HTTP methods to a link
#         """
#         methods = dict()
#         for method in self.get_available_methods():
#             proto = self.get_link_prototype_for_method(method)
#             if proto and proto.show_link():
#                 kwargs = {'use_request_url':True}
#                 kwargs = self.get_link_kwargs(**kwargs)
#                 link = proto.get_link(**kwargs)
#                 methods[method] = link
#         return methods
# 
#     def get_url_suffix(self):
#         return self.url_suffix
# 
#     def get_view_kwargs(self, **kwargs):
#         """
#         :rtype: dict
#         """
#         params = dict(self._init_kwargs)
#         params.update(kwargs)
#         return params
# 
#     def get_view(self, **kwargs):
#         """
#         :rtype: view callable
#         """
#         #TODO should this be get_endpoint_kwargs?
#         params = self.get_view_kwargs(**kwargs)
#         view = type(self).as_view(**params)
#         #allow for retreiving the endpoint from url patterns
#         view.endpoint = self
#         #thus allowing us to do: myview.endpoint.get_view(**some_new_kwargs)
#         return view
# 
#     def get_url_object(self):
#         view = self.get_view()
#         return url(self.get_url_suffix(), view, name=self.get_url_name(),)
# 
#     def get_main_link_name(self):
#         return self.get_link_prototype_for_method('GET').name
# 
# Path: hyperadmin/links.py
# class LinkCollection(list):
#     def __init__(self, endpoint):
#         self.endpoint = endpoint
#     
#     @property
#     def link_prototypes(self):
#         return self.endpoint.link_prototypes
#     
#     def add_link(self, link_name, **kwargs):
#         """
#         Adds the specified link from the resource.
#         This will only add the link if it exists and the person is allowed to view it.
#         """
#         from hyperadmin.endpoints import BaseEndpoint
#         if isinstance(link_name, BaseEndpoint):
#             try:
#                 link_name = link_name.get_main_link_name()
#             except LinkNotAvailable:
#                 return False
#         if link_name not in self.link_prototypes:
#             return False
#         endpoint_link = self.link_prototypes[link_name]
#         if not endpoint_link.show_link(**kwargs):
#             return False
#         link = endpoint_link.get_link(**kwargs)
#         self.append(link)
#         return link


# Path: hyperadmin/resources/endpoints.py
from hyperadmin.endpoints import Endpoint
from hyperadmin.links import LinkCollection



class ResourceEndpoint(Endpoint):
    @property
    def resource(self):
        return self.parent

    def create_link_collection(self):
        return LinkCollection(endpoint=self.resource)

    def get_resource_item(self, instance, **kwargs):

        kwargs.setdefault('endpoint', self)