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

[((195, 212), 'rest_framework.decorators.api_view', 'api_view', (["['GET']"], {}), "(['GET'])\n", (203, 212), False, 'from rest_framework.decorators import api_view\n'), ((341, 358), 'rest_framework.decorators.api_view', 'api_view', (["['GET']"], {}), "(['GET'])\n", (349, 358), False, 'from rest_framework.decorators import api_view\n'), ((629, 646), 'rest_framework.decorators.api_view', 'api_view', (["['GET']"], {}), "(['GET'])\n", (637, 646), False, 'from rest_framework.decorators import api_view\n'), ((989, 1007), 'rest_framework.decorators.api_view', 'api_view', (["['POST']"], {}), "(['POST'])\n", (997, 1007), False, 'from rest_framework.decorators import api_view\n'), ((1371, 1389), 'rest_framework.decorators.api_view', 'api_view', (["['POST']"], {}), "(['POST'])\n", (1379, 1389), False, 'from rest_framework.decorators import api_view\n'), ((600, 625), 'rest_framework.response.Response', 'Response', (['root_navigation'], {}), '(root_navigation)\n', (608, 625), False, 'from rest_framework.response import Response\n'), ((959, 985), 'rest_framework.response.Response', 'Response', (['token_navigation'], {}), '(token_navigation)\n', (967, 985), False, 'from rest_framework.response import Response\n'), ((1338, 1367), 'rest_framework.response.Response', 'Response', (['"""unauthorized"""', '(401)'], {}), "('unauthorized', 401)\n", (1346, 1367), False, 'from rest_framework.response import Response\n'), ((1441, 1455), 'rest_framework.response.Response', 'Response', (['"""ok"""'], {}), "('ok')\n", (1449, 1455), False, 'from rest_framework.response import Response\n'), ((436, 506), 'rest_framework.reverse.reverse', 'reverse', (['"""api_v1:redirects:redirect-list"""'], {'request': 'request', 'format': 'fmt'}), "('api_v1:redirects:redirect-list', request=request, format=fmt)\n", (443, 506), False, 'from rest_framework.reverse import reverse\n'), ((525, 582), 'rest_framework.reverse.reverse', 'reverse', (['"""api_v1:token_root"""'], {'request': 'request', 'format': 'fmt'}), "('api_v1:token_root', request=request, format=fmt)\n", (532, 582), False, 'from rest_framework.reverse import reverse\n'), ((723, 780), 'rest_framework.reverse.reverse', 'reverse', (['"""api_v1:token_auth"""'], {'request': 'request', 'format': 'fmt'}), "('api_v1:token_auth', request=request, format=fmt)\n", (730, 780), False, 'from rest_framework.reverse import reverse\n'), ((801, 861), 'rest_framework.reverse.reverse', 'reverse', (['"""api_v1:token_refresh"""'], {'request': 'request', 'format': 'fmt'}), "('api_v1:token_refresh', request=request, format=fmt)\n", (808, 861), False, 'from rest_framework.reverse import reverse\n'), ((881, 940), 'rest_framework.reverse.reverse', 'reverse', (['"""api_v1:token_verify"""'], {'request': 'request', 'format': 'fmt'}), "('api_v1:token_verify', request=request, format=fmt)\n", (888, 940), False, 'from rest_framework.reverse import reverse\n'), ((278, 329), 'rest_framework.reverse.reverse', 'reverse', (['"""api_v1:root"""'], {'request': 'request', 'format': 'fmt'}), "('api_v1:root', request=request, format=fmt)\n", (285, 329), False, 'from rest_framework.reverse import reverse\n'), ((1228, 1261), 'rest_framework.response.Response', 'Response', (["{'access': access}", '(200)'], {}), "({'access': access}, 200)\n", (1236, 1261), False, 'from rest_framework.response import Response\n'), ((1295, 1326), 'rest_framework.response.Response', 'Response', (["{'unauthorized'}", '(401)'], {}), "({'unauthorized'}, 401)\n", (1303, 1326), False, 'from rest_framework.response import Response\n')]