import os
import json
import sys
import requests
from dotenv import load_dotenv

# Path gymnastics
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "connector-superoffice"))

from superoffice_client import SuperOfficeClient

# Load ENV
load_dotenv(dotenv_path="/home/node/clawd/.env", override=True)

def surgical_update(contact_id):
    client = SuperOfficeClient()
    print(f"--- Surgical Update: Contact {contact_id} ---")
    
    # We use a MINIMAL payload. SuperOffice REST often prefers this for Stammfelder.
    # Note: Using 'contactId' as it appeared in your discovery log.
    payload = {
        "contactId": int(contact_id),
        "Department": "Surgical Update 13:20",
        "UrlAddress": "http://robo-planet.de"
    }
    
    url = f"{client.base_url}/Contact/{contact_id}"
    print(f"Sending PUT to {url} with payload: {payload}")
    
    resp = requests.put(url, headers=client.headers, json=payload)
    
    print(f"Status Code: {resp.status_code}")
    print("Full Response Body:")
    print(json.dumps(resp.json() if resp.content else {}, indent=2))

if __name__ == "__main__":
    surgical_update(2)
