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 blind_check():
    print("🕵️ Testing Manuel's Filter: contactAssociate/contactFullName eq 'RoboPlanet GmbH'")
    client = SuperOfficeClient()
    if not client.access_token:
        print("❌ Auth failed.")
        return

    # Manuel's filter logic with Count
    endpoint = "Contact?$filter=contactAssociate/contactFullName eq 'RoboPlanet GmbH'&$top=0&$count=true"
    
    print(f"📡 Querying: {endpoint}")
    try:
        resp = client._get(endpoint)
        count = resp.get('@odata.count')
        print(f"\n🎯 RESULT: Manuel's Filter found {count} accounts.")
        
        if count == 17014:
            print("✅ PERFECT MATCH! Manuel's filter matches your UI count exactly.")
        else:
            print(f"ℹ️ Delta to UI: {17014 - (count or 0)}")
            
    except Exception as e:
        print(f"❌ Manuel's filter failed: {e}")
        # Try without spaces encoded
        print("Trying with encoded spaces...")
        try:
             endpoint_enc = "Contact?$filter=contactAssociate/contactFullName eq 'RoboPlanet+GmbH'&$top=0&$count=true"
             resp = client._get(endpoint_enc)
             print(f"🎯 Encoded Result: {resp.get('@odata.count')}")
        except:
             pass

if __name__ == "__main__":
    blind_check()
