# import requests
# import os

# async def POST(request, response):
#     secret_key = "6LeDy2IpAAAAAG3DEDMywFVRq5nJhby8YFIWsAPg"
    
#     postData = await request.json()
#     gRecaptchaToken = postData.get("gRecaptchaToken", "")
#     form_id = postData.get("form_id", "")

#     print("gRecaptchaToken:", gRecaptchaToken[:10] + "...", form_id)

#     tokenValidateResponse = None
#     responseMessage = ""
#     responseDescription = ""
#     ticketNo = ""
#     submitUrl = ''
#     scoreTolerance = 0.5

#     formData = {
#         "secret": secret_key,
#         "response": gRecaptchaToken
#     }
#     try:
#         tokenValidateResponse = requests.post(
#             "https://www.google.com/recaptcha/api/siteverify",
#             data=formData
#         )

#         print("Captcha Token Result:", tokenValidateResponse.json())

#         if (tokenValidateResponse and tokenValidateResponse.json().get("success", False) 
#             and tokenValidateResponse.json().get("score", 0) > scoreTolerance):

#             submitUrl = os.environ.get("URL_FORM_SUBMIT", "")
#             submitResponse = requests.post(
#                 submitUrl,
#                 json=postData,
#                 headers={
#                     "Accept": "application/json, text/plain, */*",
#                     "Content-Type": "application/json"
#                 }
#             )

#             responseData = submitResponse.json()
#             print("Uri", submitUrl)
#             print("Payload", postData)
#             print("Response", responseData)

#             responseMessage = responseData.get("message", "")
#             responseDescription = responseData.get("description", "")
#             ticketNo = responseData.get("ticket_no", "")

#             return NextResponse.json({
#                 "status": responseData.get("status", False),
#                 "data": {
#                     "response_message": responseMessage,
#                     "response_description": responseDescription,
#                     "ticket_no": ticketNo
#                 }
#             })
#         else:
#             return NextResponse.json({
#                 "status": False,
#                 "data": {
#                     "response_message": "User Validation Failed"
#                 }
#             })
    
#     except Exception as e:
#         print("recaptcha error:", e)
#         return NextResponse.json({
#             "status": True,
#             "message": str(e),
#             "data": {
#                 "response_message": "Something Went Wrong"
#             }
#         })
