from __future__ import annotations

import uuid

# Stable namespace for deterministic Qdrant point IDs derived from record_id.
QDRANT_POINT_NAMESPACE = uuid.UUID("6ba7b810-9dad-11d1-80b4-00c04fd430c8")


def qdrant_point_id(record_id: str) -> str:
    """
    Derive a stable Qdrant point ID from an embedding record_id.

    Uses UUID v5 so retries and re-index jobs upsert the same point (TW-88).
    The returned string is a canonical UUID accepted by Qdrant.
    """
    normalized = record_id.strip()
    if not normalized:
        raise ValueError("record_id must be non-empty")
    return str(uuid.uuid5(QDRANT_POINT_NAMESPACE, f"adpilot:embedding:{normalized}"))
