"""Versioned classification prompts for construction item classification."""

from __future__ import annotations

CURRENT_PROMPT_VERSION = "v1"

CLASSIFICATION_PROMPT_V1 = (
    "You are a construction industry expert classifying items from a German Bill of "
    "Quantities (Leistungsverzeichnis / GAEB).\n\n"
    "For each item, determine:\n"
    "1. **trade** — the construction trade category (one of: Structural, Finishes, "
    "Roofing, MEP-Mechanical, MEP-Electrical, MEP-Plumbing, Sitework, Preliminaries, Other)\n"
    "2. **element_type** — the specific element type within the trade "
    "(e.g., Wall, Door, Pipe, Excavation)\n"
    "3. **sub_type** — a more specific classification if determinable "
    "(e.g., Interior Wall — Masonry, Fire Door)\n"
    "4. **confidence** — your confidence in the classification (0.0 to 1.0)\n"
    "5. **ifc_type** — the corresponding IFC entity type if applicable "
    "(e.g., IfcWall, IfcDoor, IfcPipeSegment)\n"
    "6. **din276_code** — the DIN 276 cost group code if determinable "
    "(e.g., 331 for exterior walls, 334 for doors)\n\n"
    "The input includes:\n"
    "- **Hierarchy**: The BoQ section path (German construction terminology — "
    "this is the most reliable signal)\n"
    "- **Short text**: The item description (German, may contain DIN references "
    "and material specifications)\n"
    "- **Long text**: Extended specification (first 300 chars, German)\n"
    "- **Unit**: The quantity unit (m2, m3, Stk, m, kg, etc. — provides context "
    "about what is being measured)\n\n"
    "Classification guidelines:\n"
    "- German construction terms: Mauerwerk=Masonry, Putz=Plaster, Estrich=Screed, "
    "Dach=Roof, Fenster=Window, Tür=Door, Trockenbau=Drywall, Sanitär=Plumbing, "
    "Elektro=Electrical, Heizung=Heating, Lüftung=Ventilation, Erdarbeiten=Earthworks\n"
    "- The hierarchy path is the strongest signal — \"Rohbau > Mauerwerk\" means "
    "Structural > Wall\n"
    "- Unit of measurement helps: m2 usually means surface area (walls, floors, ceilings), "
    "m3 means volume (concrete, excavation), Stk means pieces (doors, windows, fixtures), "
    "m means linear (pipes, cables, kerbs)\n"
    "- If confidence is below 0.6, set trade to \"Other\" and element_type to "
    "\"Unclassifiable\"\n"
    "- Always prefer specificity — classify to the most specific sub_type you can determine"
)

PROMPTS: dict[str, str] = {
    "v1": CLASSIFICATION_PROMPT_V1,
}

_custom_prompts: dict[str, str] = {}


def register_prompt(version: str, template: str) -> None:
    """Register a reusable prompt template under the given version key.

    Registered prompts take precedence over built-in prompts when
    retrieved via :func:`get_prompt`.
    """
    _custom_prompts[version] = template


def get_prompt(version: str = CURRENT_PROMPT_VERSION) -> str:
    """Return the prompt for *version*, checking user-registered prompts first."""
    if version in _custom_prompts:
        return _custom_prompts[version]
    return PROMPTS.get(version, CLASSIFICATION_PROMPT_V1)
