"""visaacceptancemergedspec.

This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
"""

# ruff: noqa: E501
from visaacceptancemergedspec.api_helper import (
    APIHelper,
)
from visaacceptancemergedspec.models.merchant_initiated_transaction import (
    MerchantInitiatedTransaction,
)


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

    Attributes:
        mtype (str): This field indicates whether the transaction is a
            merchant-initiated transaction or customer-initiated transaction.  Valid
            values: - **customer** - **merchant**
        credential_stored_on_file (bool): Indicates to the issuing bank two things: -
            The merchant has received consent from the cardholder to store their card
            details on file - The merchant wants the issuing bank to check out the
            card details before the merchant initiates their first transaction for
            this cardholder. The purpose of the merchant-initiated transaction is to
            ensure that the cardholder’s credentials are valid (that the card is not
            stolen or has restrictions) and that the card details are good to be
            stored on the merchant’s file for future transactions.  Valid values: -
            `true` means merchant will use this transaction to store payment
            credentials for follow-up merchant-initiated transactions. - `false`
            means merchant will not use this transaction to store payment credentials
            for follow-up merchant-initiated transactions.  **NOTE:** The value for
            this field does not correspond to any data in the TC 33 capture file5.
            This field is supported only for Visa transactions on Visa Acceptance
            through VisaNet.
        stored_credential_used (bool): Indicates to an issuing bank whether a
            merchant-initiated transaction came from a card that was already stored
            on file.  Possible values: - **true** means the merchant-initiated
            transaction came from a card that was already stored on file. - **false**
            means the merchant-initiated transaction came from a card that was not
            stored on file.
        merchant_initiated_transaction (MerchantInitiatedTransaction): The model
            property of type MerchantInitiatedTransaction.
        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",
        "credential_stored_on_file": "credentialStoredOnFile",
        "stored_credential_used": "storedCredentialUsed",
        "merchant_initiated_transaction": "merchantInitiatedTransaction",
    }

    _optionals = [
        "mtype",
        "credential_stored_on_file",
        "stored_credential_used",
        "merchant_initiated_transaction",
    ]

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

        # 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 APIHelper.SKIP
        credential_stored_on_file =\
            dictionary.get("credentialStoredOnFile")\
            if "credentialStoredOnFile" in dictionary.keys()\
                else APIHelper.SKIP
        stored_credential_used =\
            dictionary.get("storedCredentialUsed")\
            if "storedCredentialUsed" in dictionary.keys()\
                else APIHelper.SKIP
        merchant_initiated_transaction =\
            MerchantInitiatedTransaction.from_dictionary(
                dictionary.get("merchantInitiatedTransaction"))\
                if "merchantInitiatedTransaction" 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(mtype,
                   credential_stored_on_file,
                   stored_credential_used,
                   merchant_initiated_transaction,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _mtype=(
            self.mtype
            if hasattr(self, "mtype")
            else None
        )
        _credential_stored_on_file=(
            self.credential_stored_on_file
            if hasattr(self, "credential_stored_on_file")
            else None
        )
        _stored_credential_used=(
            self.stored_credential_used
            if hasattr(self, "stored_credential_used")
            else None
        )
        _merchant_initiated_transaction=(
            self.merchant_initiated_transaction
            if hasattr(self, "merchant_initiated_transaction")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"mtype={_mtype!r}, "
            f"credential_stored_on_file={_credential_stored_on_file!r}, "
            f"stored_credential_used={_stored_credential_used!r}, "
            f"merchant_initiated_transaction={_merchant_initiated_transaction!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

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