"""
Validation utilities for PowerBI MCP Server

Shared validation logic to ensure consistency across the codebase.
"""

from .constants import REFRESH_HISTORY_MIN, REFRESH_HISTORY_MAX


def validate_dax_query(query: str) -> None:
    """
    Validate that DAX query starts with EVALUATE keyword

    Args:
        query: DAX query string to validate

    Raises:
        ValueError: If query doesn't start with EVALUATE
    """
    if not query.strip().upper().startswith("EVALUATE"):
        raise ValueError(
            "DAX query must start with EVALUATE keyword. "
            'Example: "EVALUATE Sales" or "EVALUATE FILTER(Sales, Sales[Year] = 2024)"'
        )


def validate_refresh_top(top: int) -> None:
    """
    Validate refresh history top parameter

    Args:
        top: Number of refresh records to return

    Raises:
        ValueError: If top is out of valid range
    """
    if not REFRESH_HISTORY_MIN <= top <= REFRESH_HISTORY_MAX:
        raise ValueError(
            f"top must be between {REFRESH_HISTORY_MIN} and {REFRESH_HISTORY_MAX}"
        )
