"""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 AuthorizationGroup1(object):
    """Implementation of the 'AuthorizationGroup1' model.

    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.
        statement_descriptor (str): Statement descriptors to explain the charges or
            payments on bank statements.
        merchant (str): Merchant configured for authorization group to be processed
            with. > NOTE: By default if not passed, this will be the main merchant.
            # !!!! This is future documentation, for once we have multi-merchant
            payments. !!!! # # Passing different merchants in authorization groups
            will cause multi-merchant payments, # where money will be processed into
            different merchant accounts (MIDs). # # These sub-merchant must be
            configured on the main account in order to process with them.
        mtype (Type1): Type of transaction that can be performed. <table> <tbody>
            <tr> <td>PAYMENT</td>   <td>   A standard payment transaction processed
            by CellPoint.   <br/><br/>   This is the default type and represents a
            typical payment flow.   </td>   </tr>   <tr> <td>EXTERNAL</td>   <td>
            An external transaction is one that is not processed by CellPoint,   but
            by an external third-party.   <br/><br/>   CellPoint takes no part in
            this transaction and is not responsible for the state.   <br/><br/>
            This type of transaction will purely be created as an indicator to our
            system and in our   reporting applications, that a transaction has
            happened externally.   <br/><br/>   For the purposes of checking if an
            order is fully paid for, we will count external   transactions towards
            the completion. </td> </tr> </tbody> </table> > NOTE: By default, this
            will be a standard Payment.
        transactions (List[str]): List of payment transactions created against this
            authorization group.  Multiple transactions may exist in the case of
            split payment.
        skus (List[str]): Stock Keeping Unit (SKU) is a product and service
            identification code for a specific product.
        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",
        "statement_descriptor": "statementDescriptor",
        "merchant": "merchant",
        "mtype": "type",
        "transactions": "transactions",
        "skus": "skus",
    }

    _optionals = [
        "external_supplier",
        "statement_descriptor",
        "merchant",
        "mtype",
        "transactions",
        "skus",
    ]

    def __init__(
        self,
        id=None,
        total_amount=None,
        external_supplier=APIHelper.SKIP,
        statement_descriptor=APIHelper.SKIP,
        merchant=APIHelper.SKIP,
        mtype="PAYMENT",
        transactions=APIHelper.SKIP,
        skus=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a AuthorizationGroup1 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
        if statement_descriptor is not APIHelper.SKIP:
            self.statement_descriptor = statement_descriptor
        if merchant is not APIHelper.SKIP:
            self.merchant = merchant
        self.mtype = mtype
        if transactions is not APIHelper.SKIP:
            self.transactions = transactions
        if skus is not APIHelper.SKIP:
            self.skus = skus

        # 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
        statement_descriptor =\
            dictionary.get("statementDescriptor")\
            if dictionary.get("statementDescriptor")\
                else APIHelper.SKIP
        merchant =\
            dictionary.get("merchant")\
            if dictionary.get("merchant")\
                else APIHelper.SKIP
        mtype =\
            dictionary.get("type")\
            if dictionary.get("type")\
                else "PAYMENT"
        transactions =\
            dictionary.get("transactions")\
            if dictionary.get("transactions")\
                else APIHelper.SKIP
        skus =\
            dictionary.get("skus")\
            if dictionary.get("skus")\
                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,
                   statement_descriptor,
                   merchant,
                   mtype,
                   transactions,
                   skus,
                   additional_properties)

    @classmethod
    def validate(cls, dictionary):
        """Validate dictionary against class required properties

        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:
            boolean : if dictionary is valid contains required properties.

        """
        if isinstance(dictionary, cls):
            return APIHelper.is_valid_type(
                    value=dictionary.id,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.total_amount,
                    type_callable=lambda value:
                        NonNegativeAmount.validate(value),
                    is_model_dict=True)

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("id"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("totalAmount"),
                type_callable=lambda value:
                    NonNegativeAmount.validate(value),
                is_model_dict=True)

    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
        )
        _statement_descriptor=(
            self.statement_descriptor
            if hasattr(self, "statement_descriptor")
            else None
        )
        _merchant=(
            self.merchant
            if hasattr(self, "merchant")
            else None
        )
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _transactions=(
            self.transactions
            if hasattr(self, "transactions")
            else None
        )
        _skus=(
            self.skus
            if hasattr(self, "skus")
            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"statement_descriptor={_statement_descriptor!r}, "
            f"merchant={_merchant!r}, "
            f"mtype={_mtype!r}, "
            f"transactions={_transactions!r}, "
            f"skus={_skus!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
        )
        _statement_descriptor=(
            self.statement_descriptor
            if hasattr(self, "statement_descriptor")
            else None
        )
        _merchant=(
            self.merchant
            if hasattr(self, "merchant")
            else None
        )
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _transactions=(
            self.transactions
            if hasattr(self, "transactions")
            else None
        )
        _skus=(
            self.skus
            if hasattr(self, "skus")
            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"statement_descriptor={_statement_descriptor!s}, "
            f"merchant={_merchant!s}, "
            f"mtype={_mtype!s}, "
            f"transactions={_transactions!s}, "
            f"skus={_skus!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
