"""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.order_status_type import (
    OrderStatusType,
)


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

    Status on the order level.

    Attributes:
        mtype (OrderStatusType): Status of the order.  <table>   <thead>     <tr>
            <th>Type</th>       <th>Description</th>     </tr>   </thead>   <tbody>
            <tr>       <td>ACTIVE</td>       <td>Order is currently active and is
            pending payment.</td>     </tr>     <tr>       <td>CANCELED</td>
            <td>Order has been canceled. See `reason` for why order has been
            canceled.</td>     </tr>     <tr>       <td>PAID</td>       <td>Order has
            been fully paid for by the buyer. There are now transactions associated
            with the order.</td>     </tr>     <tr>       <td>FULFILLED</td>
            <td>Order has been fulfilled by the merchant.</td>     </tr>     <tr>
            <td>COMPLETED</td>       <td>Order has been marked as complete and all
            transactions have been captured.</td>     </tr>   </tbody> </table>
        reason (OrderCanceledReason): Reason that the order was canceled.  Will only
            be sent if order state is `CANCELED`.  <table>   <thead>     <tr>
            <th>Type</th>       <th>Description</th>     </tr>   </thead>   <tbody>
            <tr>       <td>ABANDONED</td>       <td>Order has been abandoned. Time is
            out to complete payment. Please create a new order.</td>     </tr>
            <tr>       <td>FULFILLMENT_FAILURE</td>       <td>Order was unable to be
            fulfilled by the merchant. All transactions have been canceled.</td>
            </tr>     <tr>       <td>FRAUD_REJECT</td>       <td>Order was canceled
            due to the detection of fraud.</td>     </tr>     <tr>
            <td>MAXIMUM_NUMBER_OF_PAYMENT_ATTEMPTS_EXCEEDED</td>       <td>Order was
            canceled because the maximum number of payment attempts has been exceeded
            on every possible payment method</td>     </tr>   </tbody> </table>
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "mtype": "type",
        "reason": "reason",
    }

    _optionals = [
        "reason",
    ]

    def __init__(
        self,
        mtype=None,
        reason=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a OrderStatus instance."""
        # Initialize members of the class
        self.mtype = mtype
        if reason is not APIHelper.SKIP:
            self.reason = reason

        # 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
        mtype =\
            dictionary.get("type")\
            if dictionary.get("type")\
                else None
        reason =\
            dictionary.get("reason")\
            if dictionary.get("reason")\
                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(mtype,
                   reason,
                   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.mtype,
                    type_callable=lambda value:
                        OrderStatusType.validate(value))

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("type"),
                type_callable=lambda value:
                    OrderStatusType.validate(value))

    def __repr__(self):
        """Return a unambiguous string representation."""
        _mtype=self.mtype
        _reason=(
            self.reason
            if hasattr(self, "reason")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"mtype={_mtype!r}, "
            f"reason={_reason!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _mtype=self.mtype
        _reason=(
            self.reason
            if hasattr(self, "reason")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"mtype={_mtype!s}, "
            f"reason={_reason!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
