"""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,
)
from cellpointapi.models.owner import Owner
from cellpointapi.models.payment_method import (
    PaymentMethod,
)


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

    A payment instrument used for voucher-based transactions.

    Attributes:
        method (PaymentMethod): Payment method type.
        id (str): The model property of type str.
        merchant_order_reference (str): Reference for identifying an order in the
            merchant's system. This is mandatory for some issuers, such as SWAV.
        issuer (str): Issuer of the voucher
        number (str): The type number of the voucher.
        mtype (VoucherType): Type of voucher
        owner (Owner): The model property of type Owner.
        amount (NonNegativeAmount): The amount available on the voucher, at the
            latest transaction event. In a refund scenario, this is the amount that
            will be refunded to this voucher.
        created_at (datetime): Date-time that asset was created.
        expires_at (datetime): Date-time that asset is set to expire.
        custom (Dict[str, str]): Custom data to attach as a pass through for the
            voucher.  **No sensative data should ever be passed in custom fields.**
            > Note: These properties are not used by CellPoint Digital for any
            payment processing and will not be passed to any acquirers.
        is_valid (bool): Indicates whether this voucher is currently valid and can be
            used for payment or refund operations. This reflects the usability of the
            voucher at the time of the request considering issuer status, activation,
            expiration and any other business rules.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "method": "method",
        "id": "id",
        "issuer": "issuer",
        "merchant_order_reference": "merchantOrderReference",
        "number": "number",
        "mtype": "type",
        "owner": "owner",
        "amount": "amount",
        "created_at": "createdAt",
        "expires_at": "expiresAt",
        "custom": "custom",
        "is_valid": "isValid",
    }

    _optionals = [
        "merchant_order_reference",
        "number",
        "mtype",
        "owner",
        "amount",
        "created_at",
        "expires_at",
        "custom",
        "is_valid",
    ]

    def __init__(
        self,
        method=None,
        id=None,
        merchant_order_reference=APIHelper.SKIP,
        number=APIHelper.SKIP,
        mtype=APIHelper.SKIP,
        owner=APIHelper.SKIP,
        amount=APIHelper.SKIP,
        created_at=APIHelper.SKIP,
        expires_at=APIHelper.SKIP,
        custom=APIHelper.SKIP,
        is_valid=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a VoucherPaymentInstrument instance."""
        # Initialize members of the class
        self.method = method
        self.id = id
        if merchant_order_reference is not APIHelper.SKIP:
            self.merchant_order_reference = merchant_order_reference
        self.issuer = "SWAV_PAYMENT_GATEWAY"
        if number is not APIHelper.SKIP:
            self.number = number
        if mtype is not APIHelper.SKIP:
            self.mtype = mtype
        if owner is not APIHelper.SKIP:
            self.owner = owner
        if amount is not APIHelper.SKIP:
            self.amount = amount
        if created_at is not APIHelper.SKIP:
            self.created_at =\
                 APIHelper.apply_datetime_converter(
                created_at, APIHelper.RFC3339DateTime)\
                 if created_at else None
        if expires_at is not APIHelper.SKIP:
            self.expires_at =\
                 APIHelper.apply_datetime_converter(
                expires_at, APIHelper.RFC3339DateTime)\
                 if expires_at else None
        if custom is not APIHelper.SKIP:
            self.custom = custom
        if is_valid is not APIHelper.SKIP:
            self.is_valid = is_valid

        # 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
        method =\
            dictionary.get("method")\
            if dictionary.get("method")\
                else None
        id =\
            dictionary.get("id")\
            if dictionary.get("id")\
                else None
        merchant_order_reference =\
            dictionary.get("merchantOrderReference")\
            if dictionary.get("merchantOrderReference")\
                else APIHelper.SKIP
        number =\
            dictionary.get("number")\
            if dictionary.get("number")\
                else APIHelper.SKIP
        mtype =\
            dictionary.get("type")\
            if dictionary.get("type")\
                else APIHelper.SKIP
        owner =\
            Owner.from_dictionary(
                dictionary.get("owner"))\
                if "owner" in dictionary.keys()\
                else APIHelper.SKIP
        amount =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("amount"))\
                if "amount" in dictionary.keys()\
                else APIHelper.SKIP
        created_at = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("createdAt")).datetime\
            if dictionary.get("createdAt") else APIHelper.SKIP
        expires_at = APIHelper.RFC3339DateTime.from_value(
            dictionary.get("expiresAt")).datetime\
            if dictionary.get("expiresAt") else APIHelper.SKIP
        custom =\
            dictionary.get("custom")\
            if dictionary.get("custom")\
                else APIHelper.SKIP
        is_valid =\
            dictionary.get("isValid")\
            if "isValid" 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(method,
                   id,
                   merchant_order_reference,
                   number,
                   mtype,
                   owner,
                   amount,
                   created_at,
                   expires_at,
                   custom,
                   is_valid,
                   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.method,
                    type_callable=lambda value:
                        PaymentMethod.validate(value)) \
                and APIHelper.is_valid_type(
                    value=dictionary.id,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                )) \
                and APIHelper.is_valid_type(
                    value=dictionary.issuer,
                    type_callable=lambda value:
                        isinstance(
                        value,
                        str,
                ))

        if not isinstance(dictionary, dict):
            return False

        return APIHelper.is_valid_type(
                value=dictionary.get("method"),
                type_callable=lambda value:
                    PaymentMethod.validate(value)) \
            and APIHelper.is_valid_type(
                value=dictionary.get("id"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            )) \
            and APIHelper.is_valid_type(
                value=dictionary.get("issuer"),
                type_callable=lambda value:
                    isinstance(
                    value,
                    str,
            ))

    def __repr__(self):
        """Return a unambiguous string representation."""
        _method=self.method
        _id=self.id
        _merchant_order_reference=(
            self.merchant_order_reference
            if hasattr(self, "merchant_order_reference")
            else None
        )
        _issuer=self.issuer
        _number=(
            self.number
            if hasattr(self, "number")
            else None
        )
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _owner=(
            self.owner
            if hasattr(self, "owner")
            else None
        )
        _amount=(
            self.amount
            if hasattr(self, "amount")
            else None
        )
        _created_at=(
            self.created_at
            if hasattr(self, "created_at")
            else None
        )
        _expires_at=(
            self.expires_at
            if hasattr(self, "expires_at")
            else None
        )
        _custom=(
            self.custom
            if hasattr(self, "custom")
            else None
        )
        _is_valid=(
            self.is_valid
            if hasattr(self, "is_valid")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"method={_method!r}, "
            f"id={_id!r}, "
            f"merchant_order_reference={_merchant_order_reference!r}, "
            f"issuer={_issuer!r}, "
            f"number={_number!r}, "
            f"mtype={_mtype!r}, "
            f"owner={_owner!r}, "
            f"amount={_amount!r}, "
            f"created_at={_created_at!r}, "
            f"expires_at={_expires_at!r}, "
            f"custom={_custom!r}, "
            f"is_valid={_is_valid!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _method=self.method
        _id=self.id
        _merchant_order_reference=(
            self.merchant_order_reference
            if hasattr(self, "merchant_order_reference")
            else None
        )
        _issuer=self.issuer
        _number=(
            self.number
            if hasattr(self, "number")
            else None
        )
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _owner=(
            self.owner
            if hasattr(self, "owner")
            else None
        )
        _amount=(
            self.amount
            if hasattr(self, "amount")
            else None
        )
        _created_at=(
            self.created_at
            if hasattr(self, "created_at")
            else None
        )
        _expires_at=(
            self.expires_at
            if hasattr(self, "expires_at")
            else None
        )
        _custom=(
            self.custom
            if hasattr(self, "custom")
            else None
        )
        _is_valid=(
            self.is_valid
            if hasattr(self, "is_valid")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"method={_method!s}, "
            f"id={_id!s}, "
            f"merchant_order_reference={_merchant_order_reference!s}, "
            f"issuer={_issuer!s}, "
            f"number={_number!s}, "
            f"mtype={_mtype!s}, "
            f"owner={_owner!s}, "
            f"amount={_amount!s}, "
            f"created_at={_created_at!s}, "
            f"expires_at={_expires_at!s}, "
            f"custom={_custom!s}, "
            f"is_valid={_is_valid!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
