"""Utility functions and helpers"""
import logging
logging.basicConfig(level=logging.INFO, format="[%(name)s] %(levelname)s: %(message)s")
logger = logging.getLogger("gi_text_summarizer")

def validate_input(text: str) -> bool:
    if not text or not text.strip():
        raise ValueError("Input text cannot be empty")
    if len(text.strip()) < 50:
        logger.info("Text too short. Returning original.")
        return False
    return True

LENGTH_TOKEN_RATIO = {"short": 0.20, "medium": 0.40, "detailed": 0.60}
LENGTH_DESCRIPTION = {
    "short": "3-4 sentences capturing only the core idea",
    "medium": "1 concise paragraph covering main points",
    "detailed": "Key insights and important details — thorough but shorter",
}

def length_mapper(length_type: str) -> str:
    return LENGTH_DESCRIPTION.get(length_type, LENGTH_DESCRIPTION["medium"])

def token_budget(length_type: str, input_tokens: int) -> int:
    ratio = LENGTH_TOKEN_RATIO.get(length_type, LENGTH_TOKEN_RATIO["medium"])
    return max(30, int(input_tokens * ratio))

OUTPUT_FORMAT_INSTRUCTIONS = {
    "text": "Return plain paragraph text",
    "bullets": "Return bullet points using dashes (-)",
    "json": '{"summary": "...", "key_points": [...]}',
}

def format_mapper(output_format: str) -> str:
    return OUTPUT_FORMAT_INSTRUCTIONS.get(output_format, OUTPUT_FORMAT_INSTRUCTIONS["text"])
