from django.http import HttpResponse

##
## Courtesy of tastypie
##
from djrest.common.helpers import json_parse


class HttpCreated(HttpResponse):
    status_code = 201

    def __init__(self, *args, **kwargs):
        location = kwargs.pop('location', '')

        super(HttpCreated, self).__init__(*args, **kwargs)
        self['Location'] = location


class HttpAccepted(HttpResponse):
    status_code = 202


class HttpNoContent(HttpResponse):
    status_code = 204


class HttpMultipleChoices(HttpResponse):
    status_code = 300


class HttpSeeOther(HttpResponse):
    status_code = 303


class HttpNotModified(HttpResponse):
    status_code = 304


class HttpBadRequest(HttpResponse):
    status_code = 400


class HttpUnauthorized(HttpResponse):
    status_code = 401


class HttpForbidden(HttpResponse):
    status_code = 403


class HttpNotFound(HttpResponse):
    status_code = 404


class HttpMethodNotAllowed(HttpResponse):
    status_code = 405


class HttpConflict(HttpResponse):
    status_code = 409


class HttpGone(HttpResponse):
    status_code = 410


class HttpTooManyRequests(HttpResponse):
    status_code = 429


class HttpApplicationError(HttpResponse):
    status_code = 500


class HttpNotImplemented(HttpResponse):
    status_code = 501


###
###
### GENERIC JSON HELPERS
###
###

class HttpJsonResponse(HttpResponse):
    def __init__(self, content, *args, **kwargs):
        super(HttpJsonResponse, self).__init__(content_type="application/json", *args, **kwargs)
        self.content = json_parse(content)


class JsonResponse(HttpResponse):
    def __init__(self, content=None, cls=HttpResponse, *args, **kwargs):
        super(JsonResponse, self).__init__(content_type="application/json", *args, **kwargs)
        self.content = json_parse(content)
        self.status_code = cls.status_code


class JsonErrorResponse(JsonResponse):
    def __init__(self, status, msg, **kwargs):
        super(JsonErrorResponse, self).__init__(content={"status": status, "msg": msg}, **kwargs)