import os
import time

import requests

CHATBOT_API_BASE = os.getenv("CHATBOT_API_BASE", "http://localhost:5000")
url = f"{CHATBOT_API_BASE}/api/agent/chat"
token = "071w198x23ict4hs1i6bl889fit5p3f7"

headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {token}",
    "device-id": "remote-check-01"
}
payload = {
    "user_query": "hello, test server connection"
}

print(f"Testing connectivity to REMOTE server: {url}")
start = time.time()

try:
    response = requests.post(url, json=payload, headers=headers, timeout=10)
    print(f"Status Code: {response.status_code}")
    print(f"Time taken: {time.time() - start:.2f}s")
    
    if response.status_code == 200:
        print("✅ Connection Successful!")
        print("Response Preview:", str(response.json())[:200])
    else:
        print("❌ Server Error:")
        print(response.text)

except Exception as e:
    print(f"❌ Connection Failed: {e}")
