from rest_framework.response import Response
from rest_framework.views import status

import logging
logger = logging.getLogger(__name__)


def validate_request_driver_data(fn):
    def decorated(*args, **kwargs):
        # args[0] == GenericView Object
        logger.error(args[0].request.data)
        first_name = args[0].request.data.get("first_name", "")
        kart_id = args[0].request.data.get("kart_id", "")
        logger.error(first_name)
        logger.error(kart_id)
        if not first_name and not kart_id:
            return Response(
                data={
                    "message": "Both first_name and kart_id are required to add a driver"
                },
                status=status.HTTP_400_BAD_REQUEST
            )
        return fn(*args, **kwargs)
    return decorated
