"""
mindbodypublicapi

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

import os
from typing import Optional

from apimatic_core.http.configurations.proxy_settings import (
    ProxySettings as CoreProxySettings,
)


class ProxySettings(CoreProxySettings):
    """A simple data model for configuring HTTP(S) proxy settings."""

    @classmethod
    def from_environment(cls) -> Optional["ProxySettings"]:
        """
        Create an instance of this class using environment-based configuration.

        This method attempts to construct and return an instance using relevant
        environment variables, if available. If the required configuration is
        not present, it may return `None` to indicate that no valid instance
        could be created.

        Returns:
            Optional[cls]: A configured instance of this class, or `None` if
            configuration data is missing or invalid.

        """
        address = os.getenv("PROXY_ADDRESS", None)
        if not address:
            return None

        port = os.getenv("PROXY_PORT", None)
        if port is not None:
            try:
                port = int(port)
            except (TypeError, ValueError):
                port = None

        return cls(
            address=address,
            port=port,
            username=os.getenv("PROXY_USERNAME", None),
            password=os.getenv("PROXY_PASSWORD", None),
        )
