import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from tenant_db import get_tenant_conn_by_dbname
from services.notification_engine import create_template, dispatch_notification

conn = get_tenant_conn_by_dbname("tenant_refaccionaria_demo")
conn.rollback()
try:
    tid = create_template(conn, 1, "test_event2", "push", "Test", "Hello {name}")
    print("Template created:", tid)
    log_ids = dispatch_notification(conn, 1, "test_event2", {"name": "World"}, recipient_type="owner")
    print("Dispatched:", log_ids)
except Exception as e:
    conn.rollback()
    print("ERROR:", e)
    import traceback
    traceback.print_exc()
finally:
    conn.close()
