import sqlite3
import json
import time

DB_PATH = "connector_queue.db"

def trigger_resync(contact_id):
    print(f"🚀 Triggering manual resync for Contact {contact_id}...")
    
    payload = {
        "Event": "contact.changed",
        "PrimaryKey": contact_id,
        "ContactId": contact_id,
        "Changes": ["UserDefinedFields", "Name"] # Dummy changes to pass filters
    }
    
    with sqlite3.connect(DB_PATH) as conn:
        conn.execute(
            "INSERT INTO jobs (event_type, payload, status) VALUES (?, ?, ?)",
            ("contact.changed", json.dumps(payload), 'PENDING')
        )
    print("✅ Job added to queue.")

if __name__ == "__main__":
    trigger_resync(6) # Bennis Playland has CRM ID 6
