"""Shared text length limits for the formal creation-knowledge pipeline."""
from __future__ import annotations

from typing import Any

BODY_TEXT_MAX_CHARS = 50_000
CLASSIFY_BODY_MAX_CHARS = 50_000
RAW_SUMMARY_MAX_CHARS = 5_000
REASON_MAX_CHARS = 10_000
DIRECTIVE_CONTEXT_MAX_CHARS = 10_000
QUERY_FILTER_REASON_MAX_CHARS = 5_000
ERROR_MESSAGE_MAX_CHARS = 5_000
TITLE_FALLBACK_MAX_CHARS = 1_000
JSON_ERROR_SNIPPET_MAX_CHARS = 5_000


def clip_text(value: Any, limit: int) -> str:
    """Return text capped at a shared business limit."""
    if value is None:
        return ""
    text = str(value)
    if limit <= 0:
        return ""
    return text[:limit]
