"""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.amount import Amount
from cellpointapi.models.payment_processor import (
    PaymentProcessor,
)
from cellpointapi.models.transaction_failure import (
    TransactionFailure,
)
from cellpointapi.models.type_2 import Type2


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

    An External Transaction is one that is not processed by CellPoint,
    but by an external third-party.
    CellPoint takes no part in this transaction and is not responsible for the state.
    This type of transaction is purely created as an indicator to our system and in
    our
    reporting applications, that a transaction has happened externally.
    For the purposes of checking if an order is fully paid for, we will count external
    transactions towards the completion.

    Attributes:
        id (str): Unique identifier for this transaction.
        order_id (str): Identifier for an order.
        mtype (Type2): Discriminator used to identify the type of transaction.
        failure (TransactionFailure): Details about a failure that happened on a
            transaction.
        created_at (datetime): When the transaction was created.
        payment_processor (PaymentProcessor): Acquirer or Payment Service Provider
            (PSP) that processed the payment.
        supplier (str): The model property of type str.
        external_type (str): The model property of type str.
        amount (Amount): The amount an item costs.
        payment_instrument (CardPaymentInstrument | ApplePayPaymentInstrument |
            PayPalPaymentInstrument | VoucherPaymentInstrument |
            WalletPaymentInstrument | UpliftPaymentInstrument): The payment
            instrument that is being used in the transaction.
        authorization_group_id (str): Authorization group ID that this transaction
            belongs to.
        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",
        "mtype": "type",
        "supplier": "supplier",
        "external_type": "externalType",
        "amount": "amount",
        "payment_instrument": "paymentInstrument",
        "order_id": "orderId",
        "failure": "failure",
        "created_at": "createdAt",
        "payment_processor": "paymentProcessor",
        "authorization_group_id": "authorizationGroupId",
    }

    _optionals = [
        "order_id",
        "failure",
        "created_at",
        "payment_processor",
        "authorization_group_id",
    ]

    def __init__(
        self,
        id=None,
        mtype=None,
        supplier=None,
        amount=None,
        payment_instrument=None,
        order_id=APIHelper.SKIP,
        failure=APIHelper.SKIP,
        created_at=APIHelper.SKIP,
        payment_processor=APIHelper.SKIP,
        authorization_group_id=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a ExternalTransaction instance."""
        # Initialize members of the class
        self.id = id
        if order_id is not APIHelper.SKIP:
            self.order_id = order_id
        self.mtype = mtype
        if failure is not APIHelper.SKIP:
            self.failure = failure
        if created_at is not APIHelper.SKIP:
            self.created_at =\
                 APIHelper.apply_datetime_converter(
                created_at, APIHelper.RFC3339DateTime)\
                 if created_at else None
        if payment_processor is not APIHelper.SKIP:
            self.payment_processor = payment_processor
        self.supplier = supplier
        self.external_type = "PROXY"
        self.amount = amount
        self.payment_instrument = payment_instrument
        if authorization_group_id is not APIHelper.SKIP:
            self.authorization_group_id = authorization_group_id

        # 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.

        """
        from cellpointapi.utilities.union_type_lookup import (
            UnionTypeLookUp,
        )

        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
        mtype =\
            dictionary.get("type")\
            if dictionary.get("type")\
                else None
        supplier =\
            dictionary.get("supplier")\
            if dictionary.get("supplier")\
                else None
        amount =\
            Amount.from_dictionary(
                dictionary.get("amount"))\
                if dictionary.get("amount") else None
        payment_instrument = APIHelper.deserialize_union_type(
            UnionTypeLookUp.get("PaymentInstrument"),
            dictionary.get("paymentInstrument"),
            False)\
            if dictionary.get("paymentInstrument") is not None\
            else None
        order_id =\
            dictionary.get("orderId")\
            if dictionary.get("orderId")\
                else APIHelper.SKIP
        failure =\
            TransactionFailure.from_dictionary(
                dictionary.get("failure"))\
                if "failure" in dictionary.keys()\
                else APIHelper.SKIP
        created_at = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("createdAt")).datetime\
            if dictionary.get("createdAt") else APIHelper.SKIP
        payment_processor =\
            PaymentProcessor.from_dictionary(
                dictionary.get("paymentProcessor"))\
                if "paymentProcessor" in dictionary.keys()\
                else APIHelper.SKIP
        authorization_group_id =\
            dictionary.get("authorizationGroupId")\
            if dictionary.get("authorizationGroupId")\
                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,
                   mtype,
                   supplier,
                   amount,
                   payment_instrument,
                   order_id,
                   failure,
                   created_at,
                   payment_processor,
                   authorization_group_id,
                   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.

        """
        from cellpointapi.utilities.union_type_lookup import (
            UnionTypeLookUp,
        )

        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.mtype,
                    type_callable=lambda value:
                        Type2.validate(value)) \
                and APIHelper.is_valid_type(
                    value=dictionary.supplier,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.external_type,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.amount,
                    type_callable=lambda value:
                        Amount.validate(value),
                    is_model_dict=True) \
                and (UnionTypeLookUp.get("PaymentInstrument")
                .validate(dictionary.payment_instrument).is_valid)

        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("type"),
                type_callable=lambda value:
                    Type2.validate(value)) \
            and APIHelper.is_valid_type(
                value=dictionary.get("supplier"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("externalType"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("amount"),
                type_callable=lambda value:
                    Amount.validate(value),
                is_model_dict=True) \
            and (UnionTypeLookUp.get("PaymentInstrument")
            .validate(dictionary.get("paymentInstrument")).is_valid)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=self.id
        _order_id=(
            self.order_id
            if hasattr(self, "order_id")
            else None
        )
        _mtype=self.mtype
        _failure=(
            self.failure
            if hasattr(self, "failure")
            else None
        )
        _created_at=(
            self.created_at
            if hasattr(self, "created_at")
            else None
        )
        _payment_processor=(
            self.payment_processor
            if hasattr(self, "payment_processor")
            else None
        )
        _supplier=self.supplier
        _external_type=self.external_type
        _amount=self.amount
        _payment_instrument=self.payment_instrument
        _authorization_group_id=(
            self.authorization_group_id
            if hasattr(self, "authorization_group_id")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"order_id={_order_id!r}, "
            f"mtype={_mtype!r}, "
            f"failure={_failure!r}, "
            f"created_at={_created_at!r}, "
            f"payment_processor={_payment_processor!r}, "
            f"supplier={_supplier!r}, "
            f"external_type={_external_type!r}, "
            f"amount={_amount!r}, "
            f"payment_instrument={_payment_instrument!r}, "
            f"authorization_group_id={_authorization_group_id!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=self.id
        _order_id=(
            self.order_id
            if hasattr(self, "order_id")
            else None
        )
        _mtype=self.mtype
        _failure=(
            self.failure
            if hasattr(self, "failure")
            else None
        )
        _created_at=(
            self.created_at
            if hasattr(self, "created_at")
            else None
        )
        _payment_processor=(
            self.payment_processor
            if hasattr(self, "payment_processor")
            else None
        )
        _supplier=self.supplier
        _external_type=self.external_type
        _amount=self.amount
        _payment_instrument=self.payment_instrument
        _authorization_group_id=(
            self.authorization_group_id
            if hasattr(self, "authorization_group_id")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"order_id={_order_id!s}, "
            f"mtype={_mtype!s}, "
            f"failure={_failure!s}, "
            f"created_at={_created_at!s}, "
            f"payment_processor={_payment_processor!s}, "
            f"supplier={_supplier!s}, "
            f"external_type={_external_type!s}, "
            f"amount={_amount!s}, "
            f"payment_instrument={_payment_instrument!s}, "
            f"authorization_group_id={_authorization_group_id!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
