"""
API Key generation utilities
"""

from typing import Tuple


def generate_api_key() -> Tuple[str, str, str]:
    """
    Generate a secure API key.
    Returns: (full_key, key_prefix, key_hash)
    """
    import secrets
    import bcrypt

    # Generate 32-byte random key
    full_key = secrets.token_urlsafe(32)
    key_prefix = full_key[:8]

    # Hash the key
    key_hash = bcrypt.hashpw(full_key.encode(), bcrypt.gensalt()).decode()

    return full_key, key_prefix, key_hash
