"""paypalserversdk.

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

# ruff: noqa: E501
from paypalserversdk.api_helper import APIHelper
from paypalserversdk.models.capture_payment_instruction import (
    CapturePaymentInstruction,
)
from paypalserversdk.models.money import Money


class CaptureRequest(object):
    """Implementation of the 'Capture Request' model.

    Captures either a portion or the full authorized amount of an authorized payment.

    Attributes:
        amount (Money): The currency and amount for a financial transaction, such as
            a balance or payment due.
        invoice_id (str): The API caller-provided external invoice number for this
            order. Appears in both the payer's transaction history and the emails
            that the payer receives.
        final_capture (bool): Indicates whether you can make additional captures
            against the authorized payment. Set to `true` if you do not intend to
            capture additional payments against the authorization. Set to `false` if
            you intend to capture additional payments against the authorization.
        payment_instruction (CapturePaymentInstruction): Any additional payment
            instructions to be consider during payment processing. This processing
            instruction is applicable for Capturing an order or Authorizing an Order.
        note_to_payer (str): An informational note about this settlement. Appears in
            both the payer's transaction history and the emails that the payer
            receives.
        soft_descriptor (str): The payment descriptor on the payer's account
            statement.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "amount": "amount",
        "invoice_id": "invoice_id",
        "final_capture": "final_capture",
        "payment_instruction": "payment_instruction",
        "note_to_payer": "note_to_payer",
        "soft_descriptor": "soft_descriptor",
    }

    _optionals = [
        "amount",
        "invoice_id",
        "final_capture",
        "payment_instruction",
        "note_to_payer",
        "soft_descriptor",
    ]

    def __init__(
        self,
        amount=APIHelper.SKIP,
        invoice_id=APIHelper.SKIP,
        final_capture=False,
        payment_instruction=APIHelper.SKIP,
        note_to_payer=APIHelper.SKIP,
        soft_descriptor=APIHelper.SKIP):
        """Initialize a CaptureRequest instance."""
        # Initialize members of the class
        if amount is not APIHelper.SKIP:
            self.amount = amount
        if invoice_id is not APIHelper.SKIP:
            self.invoice_id = invoice_id
        self.final_capture = final_capture
        if payment_instruction is not APIHelper.SKIP:
            self.payment_instruction = payment_instruction
        if note_to_payer is not APIHelper.SKIP:
            self.note_to_payer = note_to_payer
        if soft_descriptor is not APIHelper.SKIP:
            self.soft_descriptor = soft_descriptor

    @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
        amount =\
            Money.from_dictionary(
                dictionary.get("amount"))\
                if "amount" in dictionary.keys()\
                else APIHelper.SKIP
        invoice_id =\
            dictionary.get("invoice_id")\
            if dictionary.get("invoice_id")\
                else APIHelper.SKIP
        final_capture =\
            dictionary.get("final_capture")\
            if dictionary.get("final_capture")\
                else False
        payment_instruction =\
            CapturePaymentInstruction.from_dictionary(
                dictionary.get("payment_instruction"))\
                if "payment_instruction" in dictionary.keys()\
                else APIHelper.SKIP
        note_to_payer =\
            dictionary.get("note_to_payer")\
            if dictionary.get("note_to_payer")\
                else APIHelper.SKIP
        soft_descriptor =\
            dictionary.get("soft_descriptor")\
            if dictionary.get("soft_descriptor")\
                else APIHelper.SKIP

        # Return an object of this model
        return cls(amount,
                   invoice_id,
                   final_capture,
                   payment_instruction,
                   note_to_payer,
                   soft_descriptor)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _amount=(
            self.amount
            if hasattr(self, "amount")
            else None
        )
        _invoice_id=(
            self.invoice_id
            if hasattr(self, "invoice_id")
            else None
        )
        _final_capture=(
            self.final_capture
            if hasattr(self, "final_capture")
            else None
        )
        _payment_instruction=(
            self.payment_instruction
            if hasattr(self, "payment_instruction")
            else None
        )
        _note_to_payer=(
            self.note_to_payer
            if hasattr(self, "note_to_payer")
            else None
        )
        _soft_descriptor=(
            self.soft_descriptor
            if hasattr(self, "soft_descriptor")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"amount={_amount!r}, "
            f"invoice_id={_invoice_id!r}, "
            f"final_capture={_final_capture!r}, "
            f"payment_instruction={_payment_instruction!r}, "
            f"note_to_payer={_note_to_payer!r}, "
            f"soft_descriptor={_soft_descriptor!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _amount=(
            self.amount
            if hasattr(self, "amount")
            else None
        )
        _invoice_id=(
            self.invoice_id
            if hasattr(self, "invoice_id")
            else None
        )
        _final_capture=(
            self.final_capture
            if hasattr(self, "final_capture")
            else None
        )
        _payment_instruction=(
            self.payment_instruction
            if hasattr(self, "payment_instruction")
            else None
        )
        _note_to_payer=(
            self.note_to_payer
            if hasattr(self, "note_to_payer")
            else None
        )
        _soft_descriptor=(
            self.soft_descriptor
            if hasattr(self, "soft_descriptor")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"amount={_amount!s}, "
            f"invoice_id={_invoice_id!s}, "
            f"final_capture={_final_capture!s}, "
            f"payment_instruction={_payment_instruction!s}, "
            f"note_to_payer={_note_to_payer!s}, "
            f"soft_descriptor={_soft_descriptor!s}, "
            f")"
        )
