
"""
mindbodypublicapi

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

import os

from apimatic_core.authentication.header_auth import HeaderAuth


class CustomHeaderAuthentication(HeaderAuth):
    """
    An authentication handler that applies `CustomHeaderAuthentication` to
    outgoing requests. It constructs the required credential values and integrates
    with the core authentication framework.
    """

    @property
    def error_message(self):
        """Return reason about the authentication failure."""
        return "CustomHeaderAuthentication: api_key is undefined."

    def __init__(self, auth_model):
        """
        Initialize the authentication handler with credential data.

        Args:
            auth_model: The credentials object used to generate the authorization
             header.

        """
        auth_params = {}
        if auth_model is not None \
                and auth_model.api_key is not None:
            auth_params["API-Key"] = auth_model.api_key
        super().__init__(auth_params=auth_params)


class CustomHeaderAuthenticationCredentials:
    """
    A model for authentication credentials. Provides simple validation,
    cloning support, and optional construction from environment variables.
    Suitable as a pattern for other auth models.
    """

    @property
    def api_key(self):
        """
        API Key Authentication.
        """
        return self._api_key

    def __init__(self, api_key):
        """
        Initialize the credentials.

        Args:
            api_key: The api_key property value to set.

        Raises:
            ValueError: If any required value is missing.

        """
        if api_key is None:
            raise ValueError("api_key cannot be None")
        self._api_key = api_key

    def clone_with(self, api_key=None):
        """
        Return a new instance with optional value overrides.

        Args:
            api_key: The api_key property value to set.

        """
        return CustomHeaderAuthenticationCredentials(api_key or self.api_key)

    @classmethod
    def from_environment(cls):
        """
        Create credentials from environment variables, if available.

        Returns:
            A credentials instance or ``None`` if values are missing.

        """
        api_key = os.getenv(
            "API_KEY",
            None,
        )

        if (api_key is None):
            return None

        return cls(
            api_key=api_key,
        )
