import logging
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import AllowAny
from apps.calls.tasks import test_process_booking_intent
from threading import Thread


logger = logging.getLogger(__name__)

class TestBookingIntentAPIView(APIView):
    permission_classes = [AllowAny]

    def get(self, request, *args, **kwargs):
        # Trigger the booking intent task asynchronously
        # task = test_process_booking_intent.apply_async(args=[257], countdown=1)

        # run the function in the background
        # Thread(target=test_process_booking_intent, args=(194,)).start()

        # Thread(target=test_process_booking_intent, args=(216,)).start()

        # Thread(target=test_process_booking_intent, args=(139,)).start()

        # Thread(target=test_process_booking_intent, args=(215,)).start()
        # Thread(target=test_process_booking_intent, args=(213,)).start()
        # Thread(target=test_process_booking_intent, args=(206,)).start()
        # Thread(target=test_process_booking_intent, args=(205,)).start()

        logger.info("Booking intent task triggered (thread).")
        return Response({"status": "Task running async in background."}, status=202)
