import sys
import os
import json

# Absolute path setup
current_dir = os.path.dirname(os.path.abspath(__file__))
connector_dir = os.path.abspath(os.path.join(current_dir, '..'))
sys.path.insert(0, connector_dir)

from superoffice_client import SuperOfficeClient

def debug_names():
    print("🔎 Debugging Associate Names...")
    client = SuperOfficeClient()
    if not client.access_token:
        print("❌ Auth failed.")
        return

    endpoint = "Contact?$orderby=contactId desc&$top=5&$select=name,Associate/Name"
    
    print(f"📡 Querying: {endpoint}")
    contacts = client.search(endpoint)
    
    if contacts:
        for c in contacts:
            cname = c.get('name')
            assoc = c.get('Associate') or {}
            aname = assoc.get('Name')
            print(f"   🏢 Contact: {cname}")
            print(f"      👉 Associate Name: '{aname}'")
    else:
        print("❌ No contacts found.")

if __name__ == "__main__":
    debug_names()
