#!/usr/bin/env python
# encoding: utf-8


from collection_json import Collection, Data, Error, Item, Link, Query, Template
from drf_collection_json.renderers import CollectionJSONRenderer
from rest_framework.views import APIView
from rest_framework.response import Response


def reference_collection():
    """constructs a reference collection for testing"""
    link = Link("href_link", "rel_link")
    data = Data("data1", "value1")
    item = Item(href="href_item", data=[data], links=[link])
    error = Error(code=1, message="error text")
    query = Query("href_query", "rel", data=[data])
    template = Template(data=[data])
    collection = Collection(href="href_collection",
                            links=[link],
                            items=[item],
                            queries=[query],
                            template=template,
                            error=error)
    return collection


class NoSerializerCJView(APIView):
    renderer_classes = (CollectionJSONRenderer,)

    def get(self, request):
        collection = Collection(href="")
        return Response(collection)


class CollectionCJView(APIView):
    renderer_classes = (CollectionJSONRenderer,)

    def get(self, request):
        return Response(reference_collection())
