"""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.transaction_failure import (
    TransactionFailure,
)


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

    Attributes:
        processor_name (str): Name of the payment processor.
        mid (str): Merchant Id (MID) used with the payment processor.
        failure (TransactionFailure): Details about a failure that happened on a
            transaction.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "processor_name": "processorName",
        "mid": "mid",
        "failure": "failure",
    }

    _optionals = [
        "processor_name",
        "mid",
        "failure",
    ]

    def __init__(
        self,
        processor_name=APIHelper.SKIP,
        mid=APIHelper.SKIP,
        failure=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a Failover instance."""
        # Initialize members of the class
        if processor_name is not APIHelper.SKIP:
            self.processor_name = processor_name
        if mid is not APIHelper.SKIP:
            self.mid = mid
        if failure is not APIHelper.SKIP:
            self.failure = failure

        # 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
        processor_name =\
            dictionary.get("processorName")\
            if dictionary.get("processorName")\
                else APIHelper.SKIP
        mid =\
            dictionary.get("mid")\
            if dictionary.get("mid")\
                else APIHelper.SKIP
        failure =\
            TransactionFailure.from_dictionary(
                dictionary.get("failure"))\
                if "failure" 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(processor_name,
                   mid,
                   failure,
                   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 True

        if not isinstance(dictionary, dict):
            return False

        return True

    def __repr__(self):
        """Return a unambiguous string representation."""
        _processor_name=(
            self.processor_name
            if hasattr(self, "processor_name")
            else None
        )
        _mid=(
            self.mid
            if hasattr(self, "mid")
            else None
        )
        _failure=(
            self.failure
            if hasattr(self, "failure")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"processor_name={_processor_name!r}, "
            f"mid={_mid!r}, "
            f"failure={_failure!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _processor_name=(
            self.processor_name
            if hasattr(self, "processor_name")
            else None
        )
        _mid=(
            self.mid
            if hasattr(self, "mid")
            else None
        )
        _failure=(
            self.failure
            if hasattr(self, "failure")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"processor_name={_processor_name!s}, "
            f"mid={_mid!s}, "
            f"failure={_failure!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
