#!/usr/bin/env python3
"""
Test script to check API response for user 332
"""

import requests
import json

def test_api_response():
    """Test the API endpoint with user ID 332"""
    
    API_ENDPOINT = "https://api-hris.scrubbed.net/users/getUserInfo"
    
    # Test user IDs
    test_user_ids = [332, 365, 123]
    headers = {"Content-Type": "application/json"}
    
    print("Testing API endpoint...")
    print(f"Base Endpoint: {API_ENDPOINT}")
    print("-" * 50)
    
    for user_id in test_user_ids:
        url = f"{API_ENDPOINT}/{user_id}"
        print(f"\nTesting User ID: {user_id}")
        print(f"URL: {url}")
        
        try:
            response = requests.get(url, headers=headers, timeout=10, verify=False)
        
            print(f"Status Code: {response.status_code}")
            print(f"Response Headers: {dict(response.headers)}")
            print(f"Response Text: {response.text}")
            
            if response.status_code == 200:
                try:
                    json_response = response.json()
                    print(f"JSON Response: {json.dumps(json_response, indent=2)}")
                    
                    # Check for expected fields
                    if 'name' in json_response:
                        print(f"✅ User Name: {json_response['name']}")
                    else:
                        print("❌ No 'name' field in response")
                        
                    if 'user_id' in json_response:
                        print(f"✅ User ID: {json_response['user_id']}")
                    else:
                        print("❌ No 'user_id' field in response")
                        
                except json.JSONDecodeError:
                    print("❌ Response is not valid JSON")
            else:
                print(f"❌ API request failed with status {response.status_code}")
                
        except requests.exceptions.ConnectTimeout:
            print("❌ Connection timeout - API endpoint not accessible")
            print("\n📋 Expected API Response Format:")
            print("""
{
  "user_id": 365,
  "name": "Emerson Dimacutac",
  "email": "emerson.dimacutac@scrubbed.net",
  "status": "hired",
  "department": "Technology"
}
            """)
            
        except requests.exceptions.RequestException as e:
            print(f"❌ Request failed: {e}")

if __name__ == "__main__":
    test_api_response()
