# (c) cavaliba.com  - data/api - version.py


from django.conf import settings
from django.views.decorators.csrf import csrf_exempt

from app_data.api.aaa import start_api
from app_home.log import DEBUG, log

from .helper import get_cavctl_version, send_denied, send_response

# permission: p_info


#  ----------------------------------------------------------------------------
# /api/version/
#  ----------------------------------------------------------------------------
@csrf_exempt
def version(request):

    aaa_api = start_api(request, permission="p_info")
    if not aaa_api["is_allowed"]:
        return send_denied()

    log(DEBUG, aaa=aaa_api, app="api", view="version", action="GET", status="OK", data="")

    reply = {
        "version": settings.CAVALIBA_VERSION,
        "cavctl_supported_version": get_cavctl_version(),
    }
    return send_response(request, reply, 200)
