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


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

    Transaction base properties.

    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.
        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",
        "order_id": "orderId",
        "failure": "failure",
        "created_at": "createdAt",
        "payment_processor": "paymentProcessor",
    }

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

    def __init__(
        self,
        id=None,
        mtype=None,
        order_id=APIHelper.SKIP,
        failure=APIHelper.SKIP,
        created_at=APIHelper.SKIP,
        payment_processor=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a TransactionBase 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

        # 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
        mtype =\
            dictionary.get("type")\
            if dictionary.get("type")\
                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

        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,
                   order_id,
                   failure,
                   created_at,
                   payment_processor,
                   additional_properties)

    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
        )
        _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"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
        )
        _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"additional_properties={_additional_properties!s}, "
            f")"
        )
