"""Environment-based configuration loader for Pass SDK."""

import os

from .types import PassConfig


def load_config_from_env() -> PassConfig:
    """Load Pass configuration from environment variables.

    Required environment variables:
        PASS_ENDPOINT - Pass API base URL.
        PASS_ECOMMERCE_TOKEN - E-commerce token for authentication.
        PASS_CALLBACK - Callback URL for order notifications.

    Returns:
        A populated PassConfig instance.

    Raises:
        ValueError: If any required variable is missing.
    """
    endpoint = os.environ.get("PASS_ENDPOINT")
    ecommerce_token = os.environ.get("PASS_ECOMMERCE_TOKEN")
    callback = os.environ.get("PASS_CALLBACK")

    if not endpoint:
        raise ValueError("Missing environment variable: PASS_ENDPOINT")
    if not ecommerce_token:
        raise ValueError("Missing environment variable: PASS_ECOMMERCE_TOKEN")
    if not callback:
        raise ValueError("Missing environment variable: PASS_CALLBACK")

    return PassConfig(
        endpoint=endpoint,
        ecommerce_token=ecommerce_token,
        callback=callback,
    )
