"""Project naming conventions — auto-generated by Prism.

Provides constants and helpers so that all generated (and hand-written)
code refers to tables, endpoints, classes, and variables using the same
naming rules defined in the project's NamingConfig.

Do not edit manually — changes will be overwritten on next generation.
"""

from __future__ import annotations

# ---------------------------------------------------------------------------
# Configuration summary
# ---------------------------------------------------------------------------

NAMING_CONFIG: dict[str, str | dict[str, str] | list[str]] = {
    "table_style": "{{ config.table_style }}",
    "table_plural": "{{ config.table_plural }}",
    "table_prefix": "{{ config.table_prefix }}",
    "column_style": "{{ config.column_style }}",
    "fk_suffix": "{{ config.fk_suffix }}",
    "endpoint_style": "{{ config.endpoint_style }}",
    "endpoint_plural": "{{ config.endpoint_plural }}",
    "endpoint_prefix": "{{ config.endpoint_prefix }}",
    "model_suffix": "{{ config.model_suffix }}",
    "schema_suffix": "{{ config.schema_suffix }}",
    "service_suffix": "{{ config.service_suffix }}",
    "backend_var_style": "{{ config.backend_var_style }}",
    "frontend_var_style": "{{ config.frontend_var_style }}",
    "constant_style": "{{ config.constant_style }}",
    "timestamp_names": {{ config.timestamp_names }},
{% if config.abbreviations %}
    "abbreviations": {{ config.abbreviations }},
{% else %}
    "abbreviations": {},
{% endif %}
{% if config.reserved_words %}
    "reserved_words": {{ config.reserved_words }},
{% else %}
    "reserved_words": [],
{% endif %}
}

# ---------------------------------------------------------------------------
# Per-model naming look-ups
# ---------------------------------------------------------------------------

_MODEL_NAMES: dict[str, dict[str, str]] = {
{% for entry in entries %}
    "{{ entry.model_name }}": {
        "table_name": "{{ entry.table_name }}",
        "endpoint_segment": "{{ entry.endpoint_segment }}",
        "endpoint_full": "{{ entry.endpoint_full }}",
        "model_class": "{{ entry.model_class }}",
        "schema_class": "{{ entry.schema_class }}",
        "service_class": "{{ entry.service_class }}",
        "backend_var": "{{ entry.backend_var }}",
        "frontend_var": "{{ entry.frontend_var }}",
        "constant_var": "{{ entry.constant_var }}",
    },
{% endfor %}
}


# ---------------------------------------------------------------------------
# Public helpers
# ---------------------------------------------------------------------------


def get_table_name(model_name: str) -> str:
    """Return the configured table name for a model."""
    entry = _MODEL_NAMES.get(model_name)
    if entry is None:
        raise KeyError(f"Unknown model: {model_name}")
    return entry["table_name"]


def get_endpoint_path(model_name: str) -> str:
    """Return the full REST endpoint path for a model."""
    entry = _MODEL_NAMES.get(model_name)
    if entry is None:
        raise KeyError(f"Unknown model: {model_name}")
    return entry["endpoint_full"]


def get_class_name(model_name: str, kind: str = "model") -> str:
    """Return the configured class name for a model.

    Args:
        model_name: The PascalCase model name.
        kind: One of 'model', 'schema', or 'service'.
    """
    entry = _MODEL_NAMES.get(model_name)
    if entry is None:
        raise KeyError(f"Unknown model: {model_name}")
    key = f"{kind}_class"
    if key not in entry:
        raise KeyError(f"Unknown kind: {kind}")
    return entry[key]


def get_variable_name(model_name: str, target: str = "backend") -> str:
    """Return the configured variable name for a model.

    Args:
        model_name: The PascalCase model name.
        target: One of 'backend', 'frontend', or 'constant'.
    """
    entry = _MODEL_NAMES.get(model_name)
    if entry is None:
        raise KeyError(f"Unknown model: {model_name}")
    key = f"{target}_var"
    if key not in entry:
        raise KeyError(f"Unknown target: {target}")
    return entry[key]
