def time_to_minutes(time_str: str) -> int:
    """Convert a time string in HH:MM format to the total number of minutes.

    Parameters
    ----------
    time_str : str
        A string representing time in 24-hour format (HH:MM).

    Returns
    -------
    int or None
        The total number of minutes represented by the input string, or None
        if the input format is invalid or represents an invalid time.

    """
    # Define constants for validation
    HOURS_IN_A_DAY = 24  # Total hours in a day
    MINUTES_IN_AN_HOUR = 60  # Total minutes in an hour

    # Check if the input is a string
    if not isinstance(time_str, str):
        return None

    # Check if the string is in the correct format
    # (5 characters with ':' at index 2)
    if len(time_str) != 5 or time_str[2] != ":":
        return None

    # Split the string into hours and minutes
    hours, minutes = time_str.split(":", 1)

    # Check if hours and minutes are digit strings
    if not hours.isdigit() or not minutes.isdigit():
        return None

    # Convert hours and minutes to integers
    hours, minutes = int(hours), int(minutes)

    # Check if hours and minutes fall within valid ranges
    # and calculate total minutes
    if 0 <= hours < HOURS_IN_A_DAY and 0 <= minutes < MINUTES_IN_AN_HOUR:
        return hours * MINUTES_IN_AN_HOUR + minutes

    return None

def classify_peak_hours(minutes_since_midnight: int) -> str:
    """Classify a given time in minutes as 'peak' or 'off-peak'.

    Peak hours are defined as [07:00-09:00) and [17:00-19:00).

    Parameters
    ----------
    minutes_since_midnight : int
        The number of minutes elapsed since midnight.

    Returns
    -------
    str or None
        Returns "peak" if the time falls within peak hours, "off-peak" otherwise.
        Returns None for invalid inputs.

    """
    # Define constants
    MINUTES_IN_A_DAY = 24 * 60  # Total minutes in a day (00:00 to 23:59)

    # Validate the input is an integer
    if not isinstance(minutes_since_midnight, int):
        return None

    # Validate the input is within the range of 0 to MINUTES_IN_A_DAY
    if not (0 <= minutes_since_midnight < MINUTES_IN_A_DAY):
        return None

    # Define peak hour ranges in minutes
    morning_peak_start = 7 * 60  # 07:00 in minutes
    morning_peak_end = 9 * 60  # 09:00 in minutes
    evening_peak_start = 17 * 60  # 17:00 in minutes
    evening_peak_end = 19 * 60  # 19:00 in minutes

    # Check if the time is within morning or evening peak hours
    is_morning_peak = morning_peak_start <= minutes_since_midnight < morning_peak_end
    is_evening_peak = evening_peak_start <= minutes_since_midnight < evening_peak_end

    if is_morning_peak or is_evening_peak:
        return "peak"

    return "off-peak"
