"""Test the can-delete user endpoint"""
import requests
import sys

BASE_URL = "http://localhost:8000"

def test_can_delete_user():
    # First, login as admin
    login_response = requests.post(
        f"{BASE_URL}/auth/login",
        json={
            "email": "admin@vfx.com",
            "password": "admin123"
        }
    )
    
    if login_response.status_code != 200:
        print(f"Login failed: {login_response.status_code}")
        print(login_response.json())
        return
    
    token = login_response.json()["access_token"]
    headers = {"Authorization": f"Bearer {token}"}
    
    # Test checking if user 5 can be deleted
    user_id = 5
    response = requests.get(
        f"{BASE_URL}/users/{user_id}/can-delete",
        headers=headers
    )
    
    print(f"\nChecking if user {user_id} can be deleted:")
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.json()}")
    
    if response.status_code == 200:
        data = response.json()
        print(f"\nCan delete: {data['can_delete']}")
        if not data['can_delete']:
            print(f"Reason: {data['reason']}")
            print(f"Project memberships: {data['project_memberships']}")
            print(f"Task assignments: {data['task_assignments']}")

if __name__ == "__main__":
    test_can_delete_user()
