from rest_framework.decorators import api_view
from rest_framework.response import Response


@api_view(["POST", "GET"])
def email_notification_settings(request):
    EMAIL_NOTIFICATION_CATEGORIES = "email_notification_categories"
    if request.method == "POST":
        request.user.additional_json_data[EMAIL_NOTIFICATION_CATEGORIES] = request.data
        request.user.save()
    return Response(
        status=200,
        data=request.user.additional_json_data.get(EMAIL_NOTIFICATION_CATEGORIES, []),
    )
