"""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.authorization_group import (
    AuthorizationGroup,
)
from cellpointapi.models.non_negative_amount import (
    NonNegativeAmount,
)
from cellpointapi.models.refund_reason import (
    RefundReason,
)


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

    Contains the refund request object.

    Attributes:
        id (str): Unique identifier for this refund action.
        reason (RefundReason): Optional merchant-defined reason for the refund.
        refund_type (RefundType): Type of refund to do, either partial or full. The
            actual refund however can be for any amount regardless of this type. The
            reason being that there may be fees so the refund can be full even though
            some amount is kept.
        amount (NonNegativeAmount): Amount to refund. - The currency must be the same
            as the one used to pay. - The value must be equal to or smaller than the
            total paid amount minus the already refunded amount.
        authorization_groups (List[AuthorizationGroup]): A means of grouping line
            items together into separate authorizations for Aggregate Payments.
        channel (str): Merchant configured channels, must be 1-5 alpha-characters.
            Typical examples include: - IBE - Internet Booking Engine - CC - Customer
            Care
        note (str): Optional note to be added to the transaction.
        custom (Dict[str, Any]): Custom data to send as part of the refund request.
        additional_properties (Dict[str, Any]): The additional properties for the
            model.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "refund_type": "refundType",
        "amount": "amount",
        "id": "id",
        "reason": "reason",
        "authorization_groups": "authorizationGroups",
        "channel": "channel",
        "note": "note",
        "custom": "custom",
    }

    _optionals = [
        "id",
        "reason",
        "authorization_groups",
        "channel",
        "note",
        "custom",
    ]

    def __init__(
        self,
        refund_type=None,
        amount=None,
        id=APIHelper.SKIP,
        reason=APIHelper.SKIP,
        authorization_groups=APIHelper.SKIP,
        channel=APIHelper.SKIP,
        note=APIHelper.SKIP,
        custom=APIHelper.SKIP,
        additional_properties=None):
        """Initialize a RefundRequest instance."""
        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id
        if reason is not APIHelper.SKIP:
            self.reason = reason
        self.refund_type = refund_type
        self.amount = amount
        if authorization_groups is not APIHelper.SKIP:
            self.authorization_groups = authorization_groups
        if channel is not APIHelper.SKIP:
            self.channel = channel
        if note is not APIHelper.SKIP:
            self.note = note
        if custom is not APIHelper.SKIP:
            self.custom = custom

        # 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
        refund_type =\
            dictionary.get("refundType")\
            if dictionary.get("refundType")\
                else None
        amount =\
            NonNegativeAmount.from_dictionary(
                dictionary.get("amount"))\
                if dictionary.get("amount") else None
        id =\
            dictionary.get("id")\
            if dictionary.get("id")\
                else APIHelper.SKIP
        reason =\
            RefundReason.from_dictionary(
                dictionary.get("reason"))\
                if "reason" in dictionary.keys()\
                else APIHelper.SKIP
        authorization_groups = None
        if dictionary.get("authorizationGroups") is not None:
            authorization_groups = [
                AuthorizationGroup.from_dictionary(x)
                    for x in dictionary.get("authorizationGroups")
            ]
        else:
            authorization_groups = APIHelper.SKIP
        channel =\
            dictionary.get("channel")\
            if dictionary.get("channel")\
                else APIHelper.SKIP
        note =\
            dictionary.get("note")\
            if dictionary.get("note")\
                else APIHelper.SKIP
        custom =\
            dictionary.get("custom")\
            if dictionary.get("custom")\
                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(refund_type,
                   amount,
                   id,
                   reason,
                   authorization_groups,
                   channel,
                   note,
                   custom,
                   additional_properties)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _reason=(
            self.reason
            if hasattr(self, "reason")
            else None
        )
        _refund_type=self.refund_type
        _amount=self.amount
        _authorization_groups=(
            self.authorization_groups
            if hasattr(self, "authorization_groups")
            else None
        )
        _channel=(
            self.channel
            if hasattr(self, "channel")
            else None
        )
        _note=(
            self.note
            if hasattr(self, "note")
            else None
        )
        _custom=(
            self.custom
            if hasattr(self, "custom")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"reason={_reason!r}, "
            f"refund_type={_refund_type!r}, "
            f"amount={_amount!r}, "
            f"authorization_groups={_authorization_groups!r}, "
            f"channel={_channel!r}, "
            f"note={_note!r}, "
            f"custom={_custom!r}, "
            f"additional_properties={_additional_properties!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _reason=(
            self.reason
            if hasattr(self, "reason")
            else None
        )
        _refund_type=self.refund_type
        _amount=self.amount
        _authorization_groups=(
            self.authorization_groups
            if hasattr(self, "authorization_groups")
            else None
        )
        _channel=(
            self.channel
            if hasattr(self, "channel")
            else None
        )
        _note=(
            self.note
            if hasattr(self, "note")
            else None
        )
        _custom=(
            self.custom
            if hasattr(self, "custom")
            else None
        )
        _additional_properties=self.additional_properties
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"reason={_reason!s}, "
            f"refund_type={_refund_type!s}, "
            f"amount={_amount!s}, "
            f"authorization_groups={_authorization_groups!s}, "
            f"channel={_channel!s}, "
            f"note={_note!s}, "
            f"custom={_custom!s}, "
            f"additional_properties={_additional_properties!s}, "
            f")"
        )
