"""
reset_similarity_edges.py
=========================
Hapus semua edge SIMILAR_* agar bisa rebuild bersih setelah tuning gate.

Cara menjalankan:
  source venv/bin/activate
  python reset_similarity_edges.py
"""

import os
from dotenv import load_dotenv
from neo4j import GraphDatabase


def main() -> int:
    load_dotenv()
    uri = os.getenv("NEO4J_URI", "")
    user = os.getenv("NEO4J_USERNAME", "neo4j")
    pwd = os.getenv("NEO4J_PASSWORD", "")

    if not all([uri, user, pwd]):
        print("❌ ERROR: Kredensial Neo4j belum lengkap di file .env")
        return 1

    driver = GraphDatabase.driver(uri, auth=(user, pwd))
    cypher = """
    MATCH ()-[r]->()
    WHERE type(r) STARTS WITH 'SIMILAR_'
    WITH count(r) AS before
    MATCH ()-[r2]->()
    WHERE type(r2) STARTS WITH 'SIMILAR_'
    DELETE r2
    RETURN before
    """

    with driver.session() as session:
        rec = session.run(cypher).single()
        before = rec["before"] if rec else 0

    driver.close()
    print(f"✅ Deleted SIMILAR_* edges: {before}")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
