#!/usr/bin/env python3
"""
Test script to check vTiger contact data
"""
import asyncio
import sys
sys.path.insert(0, '/Users/christianthomas/DEV/bmc_hub_dev')

from app.services.vtiger_service import VTigerService

async def test_contact():
    vtiger = VTigerService()
    
    # Fetch contact by email
    query = "SELECT id, firstname, lastname, email, account_id FROM Contacts WHERE email = 'accounting@arbodania.com';"
    print(f"Query: {query}")
    
    result = await vtiger.query(query)
    
    if result:
        contact = result[0]
        print(f"\n✅ Contact found:")
        print(f"  ID: {contact.get('id')}")
        print(f"  Name: {contact.get('firstname')} {contact.get('lastname')}")
        print(f"  Email: {contact.get('email')}")
        print(f"  Account ID: {contact.get('account_id')}")
        
        # Now fetch the account details
        account_id = contact.get('account_id')
        if account_id:
            account_query = f"SELECT id, accountname FROM Accounts WHERE id = '{account_id}';"
            print(f"\nFetching account: {account_query}")
            account_result = await vtiger.query(account_query)
            
            if account_result:
                account = account_result[0]
                print(f"\n✅ Account found:")
                print(f"  ID: {account.get('id')}")
                print(f"  Name: {account.get('accountname')}")
    else:
        print("❌ Contact not found")

if __name__ == "__main__":
    asyncio.run(test_contact())
