from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework.reverse import reverse
from rest_framework_simplejwt.tokens import RefreshToken


@api_view(['GET'])
def root(request, fmt=None):
    return Response({
        'v1': reverse('api_v1:root', request=request, format=fmt),
    })


@api_view(['GET'])
def v1_root(request, fmt=None):
    root_navigation = {
        'redirects': reverse('api_v1:redirects:redirect-list', request=request, format=fmt),
        'token': reverse('api_v1:token_root', request=request, format=fmt)
    }
    return Response(root_navigation)


@api_view(['GET'])
def token_root(request, fmt=None):
    token_navigation = {
        'auth': reverse('api_v1:token_auth', request=request, format=fmt),
        'refresh': reverse('api_v1:token_refresh', request=request, format=fmt),
        'verify': reverse('api_v1:token_verify', request=request, format=fmt),
    }
    return Response(token_navigation)


@api_view(['POST'])
def token_refresh(request):
    token = request.COOKIES.get("burl_refresh_token")
    if token:
        refresh = RefreshToken(str(token))
        access = str(refresh.access_token)
        if access:
            return Response({"access": access}, 200)
        else:
            return Response({"unauthorized"}, 401)
    return Response("unauthorized", 401)


@api_view(['POST'])
def token_refresh_revoke(_request):
    response = Response("ok")
    response.delete_cookie("burl_refresh_token")
    return response

[((7, 1, 7, 18), 'rest_framework.decorators.api_view', 'api_view', ({(7, 10, 7, 17): "['GET']"}, {}), "(['GET'])", False, 'from rest_framework.decorators import api_view\n'), ((14, 1, 14, 18), 'rest_framework.decorators.api_view', 'api_view', ({(14, 10, 14, 17): "['GET']"}, {}), "(['GET'])", False, 'from rest_framework.decorators import api_view\n'), ((23, 1, 23, 18), 'rest_framework.decorators.api_view', 'api_view', ({(23, 10, 23, 17): "['GET']"}, {}), "(['GET'])", False, 'from rest_framework.decorators import api_view\n'), ((33, 1, 33, 19), 'rest_framework.decorators.api_view', 'api_view', ({(33, 10, 33, 18): "['POST']"}, {}), "(['POST'])", False, 'from rest_framework.decorators import api_view\n'), ((46, 1, 46, 19), 'rest_framework.decorators.api_view', 'api_view', ({(46, 10, 46, 18): "['POST']"}, {}), "(['POST'])", False, 'from rest_framework.decorators import api_view\n'), ((20, 11, 20, 36), 'rest_framework.response.Response', 'Response', ({(20, 20, 20, 35): 'root_navigation'}, {}), '(root_navigation)', False, 'from rest_framework.response import Response\n'), ((30, 11, 30, 37), 'rest_framework.response.Response', 'Response', ({(30, 20, 30, 36): 'token_navigation'}, {}), '(token_navigation)', False, 'from rest_framework.response import Response\n'), ((43, 11, 43, 40), 'rest_framework.response.Response', 'Response', ({(43, 20, 43, 34): '"""unauthorized"""', (43, 36, 43, 39): '(401)'}, {}), "('unauthorized', 401)", False, 'from rest_framework.response import Response\n'), ((48, 15, 48, 29), 'rest_framework.response.Response', 'Response', ({(48, 24, 48, 28): '"""ok"""'}, {}), "('ok')", False, 'from rest_framework.response import Response\n'), ((17, 21, 17, 91), 'rest_framework.reverse.reverse', 'reverse', (), '', False, 'from rest_framework.reverse import reverse\n'), ((18, 17, 18, 74), 'rest_framework.reverse.reverse', 'reverse', (), '', False, 'from rest_framework.reverse import reverse\n'), ((26, 16, 26, 73), 'rest_framework.reverse.reverse', 'reverse', (), '', False, 'from rest_framework.reverse import reverse\n'), ((27, 19, 27, 79), 'rest_framework.reverse.reverse', 'reverse', (), '', False, 'from rest_framework.reverse import reverse\n'), ((28, 18, 28, 77), 'rest_framework.reverse.reverse', 'reverse', (), '', False, 'from rest_framework.reverse import reverse\n'), ((10, 14, 10, 65), 'rest_framework.reverse.reverse', 'reverse', (), '', False, 'from rest_framework.reverse import reverse\n'), ((40, 19, 40, 52), 'rest_framework.response.Response', 'Response', ({(40, 28, 40, 46): "{'access': access}", (40, 48, 40, 51): '(200)'}, {}), "({'access': access}, 200)", False, 'from rest_framework.response import Response\n'), ((42, 19, 42, 50), 'rest_framework.response.Response', 'Response', ({(42, 28, 42, 44): "{'unauthorized'}", (42, 46, 42, 49): '(401)'}, {}), "({'unauthorized'}, 401)", False, 'from rest_framework.response import Response\n')]