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


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