from wagtail.api.v2.endpoints import PagesAPIEndpoint
from wagtail.api.v2.serializers import PageSerializer
from rest_framework.fields import Field
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.wagtailimages.api.v2.endpoints import ImagesAPIEndpoint
from wagtail.wagtaildocs.api.v2.endpoints import DocumentsAPIEndpoint

# Create the router. "wagtailapi" is the URL namespace
api_router = WagtailAPIRouter('wagtailapi')

# Add the three endpoints using the "register_endpoint" method.
# The first parameter is the name of the endpoint (eg. pages, images). This
# is used in the URL of the endpoint
# The second parameter is the endpoint class that handles the requests

class ExtendedPagesAPIEndpoint(PagesAPIEndpoint):
  meta_fields = PagesAPIEndpoint.meta_fields + [
    'url_path',
    'url',
  ]

  def get_queryset(self):
    qs = super(ExtendedPagesAPIEndpoint, self).get_queryset()
    print(qs.query)
    return qs

api_router.register_endpoint('shows', PagesAPIEndpoint)
api_router.register_endpoint('pages', ExtendedPagesAPIEndpoint)
api_router.register_endpoint('images', ImagesAPIEndpoint)
api_router.register_endpoint('documents', DocumentsAPIEndpoint)
