"""cellpointapi.

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

# ruff: noqa: E501
from cellpointapi.api_helper import APIHelper
from cellpointapi.models.non_negative_amount import (
    NonNegativeAmount,
)


class AuthorizationGroup(object):
    """Implementation of the 'AuthorizationGroup' model.

    A means of grouping line items together into separate authorizations for
    Aggregate Payments.

    Attributes:
        id (str): Unique id within the order for the authorization group. If an
            authorization group exists, all line items must correspond to an
            appropriate authorization group.
        total_amount (NonNegativeAmount): Total amount of authorization. Should match
            the total when adding all line items with authorization group identifier.
        external_supplier (str): Should only be specified for payments handled by an
            external supplier.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "id": "id",
        "total_amount": "totalAmount",
        "external_supplier": "externalSupplier",
    }

    _optionals = [
        "external_supplier",
    ]

    def __init__(
        self,
        id=None,
        total_amount=None,
        external_supplier=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a AuthorizationGroup instance."""
        # Initialize members of the class
        self.id = id
        self.total_amount = total_amount
        if external_supplier is not APIHelper.SKIP:
            self.external_supplier = external_supplier

        # Add additional model properties to the instance
        if additional_properties is None:
            additional_properties = {}
        self.additional_properties = additional_properties

    @classmethod
    def from_dictionary(cls,
                        dictionary):
        """Create an instance of this model from a dictionary

        Args:
            dictionary (dictionary): A dictionary representation of the object
            as obtained from the deserialization of the server's response. The
            keys MUST match property names in the API description.

        Returns:
            object: An instance of this structure class.

        """
        if not isinstance(dictionary, dict) or dictionary is None:
            return None

        # Extract variables from the dictionary
        id =\
            dictionary.get("id")\
            if dictionary.get("id")\
                else None
        total_amount =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("totalAmount"))\
                if dictionary.get("totalAmount") else None
        external_supplier =\
            dictionary.get("externalSupplier")\
            if dictionary.get("externalSupplier")\
                else APIHelper.SKIP

        additional_properties = APIHelper.get_additional_properties(
            dictionary={k: v for k, v in dictionary.items()
                        if k not in cls._names.values()},
            unboxing_function=lambda value: value)

        # Return an object of this model
        return cls(id,
                   total_amount,
                   external_supplier,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=self.id
        _total_amount=self.total_amount
        _external_supplier=(
            self.external_supplier
            if hasattr(self, "external_supplier")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"total_amount={_total_amount!r}, "
            f"external_supplier={_external_supplier!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=self.id
        _total_amount=self.total_amount
        _external_supplier=(
            self.external_supplier
            if hasattr(self, "external_supplier")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"total_amount={_total_amount!s}, "
            f"external_supplier={_external_supplier!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
