"""Test script to verify custom task type deletion"""
import requests
import json

BASE_URL = "http://localhost:8000"

def test_delete_custom_task_type():
    """Test deleting a custom task type"""
    
    # First, login to get token
    login_response = requests.post(
        f"{BASE_URL}/auth/login",
        data={
            "username": "admin",
            "password": "admin123"
        }
    )
    
    if login_response.status_code != 200:
        print(f"Login failed: {login_response.status_code}")
        print(login_response.text)
        return
    
    token = login_response.json()["access_token"]
    headers = {"Authorization": f"Bearer {token}"}
    
    # Get project ID (assuming project 1 exists)
    project_id = 1
    
    # First, add a custom task type
    print("\n1. Adding a custom task type...")
    add_response = requests.post(
        f"{BASE_URL}/projects/{project_id}/custom-task-types",
        headers=headers,
        json={
            "task_type": "test_delete_type",
            "category": "asset"
        }
    )
    print(f"Add response: {add_response.status_code}")
    if add_response.status_code == 201:
        print("Custom task type added successfully")
    else:
        print(f"Error: {add_response.text}")
    
    # Now try to delete it
    print("\n2. Deleting the custom task type...")
    delete_response = requests.delete(
        f"{BASE_URL}/projects/{project_id}/custom-task-types/test_delete_type",
        headers=headers,
        params={"category": "asset"}
    )
    print(f"Delete response: {delete_response.status_code}")
    
    if delete_response.status_code == 200:
        print("✓ Custom task type deleted successfully!")
        print(json.dumps(delete_response.json(), indent=2))
    else:
        print(f"✗ Delete failed: {delete_response.status_code}")
        print(delete_response.text)

if __name__ == "__main__":
    test_delete_custom_task_type()
