"""
Utility functions for the zsz_package
"""

import requests
from typing import Optional


def hello(name: str = "World") -> str:
    """
    Generate a greeting message.

    Args:
        name: The name to greet (default: "World")

    Returns:
        A greeting message
    """
    message = f"Hello, {name}!"
    print(message)
    return message


def greet(name: str, language: str = "en") -> str:
    """
    Greet someone in different languages.

    Args:
        name: The name to greet
        language: The language code (en, es, fr, de, zh)

    Returns:
        A greeting in the specified language
    """
    greetings = {
        "en": "Hello",
        "es": "Hola",
        "fr": "Bonjour",
        "de": "Hallo",
        "zh": "你好",
    }
    greeting = greetings.get(language, greetings["en"])
    message = f"{greeting}, {name}!"
    print(message)
    return message


def fetch_url(url: str, timeout: int = 10) -> Optional[str]:
    """
    Fetch content from a URL.

    Args:
        url: The URL to fetch
        timeout: Request timeout in seconds

    Returns:
        The response text, or None if the request fails
    """
    try:
        response = requests.get(url, timeout=timeout)
        response.raise_for_status()
        return response.text
    except requests.RequestException as e:
        print(f"Error fetching URL: {e}")
        return None
