"""
Basic Kilit usage example.

This example shows how to use Kilit in a simple Python application.
"""

from kilit import Credentials


def main():
    # Load encrypted credentials
    creds = Credentials("config/credentials.json.enc")
    
    # Get configuration values
    db_host = creds.get("database.host", "localhost")
    db_port = creds.get("database.port", 5432)
    db_user = creds.require("database.username")  # Raises if missing
    db_password = creds.require("database.password")
    
    # Use in your application
    print(f"Connecting to database at {db_host}:{db_port}")
    print(f"Username: {db_user}")
    print(f"Password: {'*' * len(db_password)}")
    
    # Get API keys
    api_key = creds.get("api.key")
    if api_key:
        print(f"API Key: {api_key[:10]}...")
    
    # Get nested configuration
    email_config = {
        "host": creds.get("email.smtp.host", "smtp.gmail.com"),
        "port": creds.get("email.smtp.port", 587),
        "username": creds.get("email.username"),
        "password": creds.get("email.password"),
    }
    
    print(f"Email SMTP: {email_config['host']}:{email_config['port']}")


if __name__ == "__main__":
    main()
