"""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.link_description import (
    LinkDescription,
)
from paypalserversdk.models.money import Money
from paypalserversdk.models.plan_details import (
    PlanDetails,
)
from paypalserversdk.models.subscriber import (
    Subscriber,
)
from paypalserversdk.models.subscription_billing_information import (
    SubscriptionBillingInformation,
)


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

    The subscription details.

    Attributes:
        id (str): The PayPal-generated ID for the subscription.
        plan_id (str): The ID of the plan.
        start_time (str): The date and time, in [Internet date and time
            format](https://tools.ietf.org/html/rfc3339#section-5.6). Seconds are
            required while fractional seconds are optional. Note: The regular
            expression provides guidance but does not reject all invalid dates.
        quantity (str): The quantity of the product in the subscription.
        shipping_amount (Money): The currency and amount for a financial transaction,
            such as a balance or payment due.
        subscriber (Subscriber): The subscriber response information.
        billing_info (SubscriptionBillingInformation): The billing details for the
            subscription. If the subscription was or is active, these fields are
            populated.
        create_time (str): The date and time, in [Internet date and time
            format](https://tools.ietf.org/html/rfc3339#section-5.6). Seconds are
            required while fractional seconds are optional. Note: The regular
            expression provides guidance but does not reject all invalid dates.
        update_time (str): The date and time, in [Internet date and time
            format](https://tools.ietf.org/html/rfc3339#section-5.6). Seconds are
            required while fractional seconds are optional. Note: The regular
            expression provides guidance but does not reject all invalid dates.
        custom_id (str): The custom id for the subscription. Can be invoice id.
        plan_overridden (bool): Indicates whether the subscription has overridden any
            plan attributes.
        plan (PlanDetails): The plan details.
        links (List[LinkDescription]): An array of request-related [HATEOAS
            links](/docs/api/reference/api-responses/#hateoas-links).

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "id": "id",
        "plan_id": "plan_id",
        "start_time": "start_time",
        "quantity": "quantity",
        "shipping_amount": "shipping_amount",
        "subscriber": "subscriber",
        "billing_info": "billing_info",
        "create_time": "create_time",
        "update_time": "update_time",
        "custom_id": "custom_id",
        "plan_overridden": "plan_overridden",
        "plan": "plan",
        "links": "links",
    }

    _optionals = [
        "id",
        "plan_id",
        "start_time",
        "quantity",
        "shipping_amount",
        "subscriber",
        "billing_info",
        "create_time",
        "update_time",
        "custom_id",
        "plan_overridden",
        "plan",
        "links",
    ]

    def __init__(
        self,
        id=APIHelper.SKIP,
        plan_id=APIHelper.SKIP,
        start_time=APIHelper.SKIP,
        quantity=APIHelper.SKIP,
        shipping_amount=APIHelper.SKIP,
        subscriber=APIHelper.SKIP,
        billing_info=APIHelper.SKIP,
        create_time=APIHelper.SKIP,
        update_time=APIHelper.SKIP,
        custom_id=APIHelper.SKIP,
        plan_overridden=APIHelper.SKIP,
        plan=APIHelper.SKIP,
        links=APIHelper.SKIP):
        """Initialize a Subscription instance."""
        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id
        if plan_id is not APIHelper.SKIP:
            self.plan_id = plan_id
        if start_time is not APIHelper.SKIP:
            self.start_time = start_time
        if quantity is not APIHelper.SKIP:
            self.quantity = quantity
        if shipping_amount is not APIHelper.SKIP:
            self.shipping_amount = shipping_amount
        if subscriber is not APIHelper.SKIP:
            self.subscriber = subscriber
        if billing_info is not APIHelper.SKIP:
            self.billing_info = billing_info
        if create_time is not APIHelper.SKIP:
            self.create_time = create_time
        if update_time is not APIHelper.SKIP:
            self.update_time = update_time
        if custom_id is not APIHelper.SKIP:
            self.custom_id = custom_id
        if plan_overridden is not APIHelper.SKIP:
            self.plan_overridden = plan_overridden
        if plan is not APIHelper.SKIP:
            self.plan = plan
        if links is not APIHelper.SKIP:
            self.links = links

    @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
        id =\
            dictionary.get("id")\
            if dictionary.get("id")\
                else APIHelper.SKIP
        plan_id =\
            dictionary.get("plan_id")\
            if dictionary.get("plan_id")\
                else APIHelper.SKIP
        start_time =\
            dictionary.get("start_time")\
            if dictionary.get("start_time")\
                else APIHelper.SKIP
        quantity =\
            dictionary.get("quantity")\
            if dictionary.get("quantity")\
                else APIHelper.SKIP
        shipping_amount =\
            Money.from_dictionary(
                dictionary.get("shipping_amount"))\
                if "shipping_amount" in dictionary.keys()\
                else APIHelper.SKIP
        subscriber =\
            Subscriber.from_dictionary(
                dictionary.get("subscriber"))\
                if "subscriber" in dictionary.keys()\
                else APIHelper.SKIP
        billing_info =\
            SubscriptionBillingInformation.from_dictionary(
                dictionary.get("billing_info"))\
                if "billing_info" in dictionary.keys()\
                else APIHelper.SKIP
        create_time =\
            dictionary.get("create_time")\
            if dictionary.get("create_time")\
                else APIHelper.SKIP
        update_time =\
            dictionary.get("update_time")\
            if dictionary.get("update_time")\
                else APIHelper.SKIP
        custom_id =\
            dictionary.get("custom_id")\
            if dictionary.get("custom_id")\
                else APIHelper.SKIP
        plan_overridden =\
            dictionary.get("plan_overridden")\
            if "plan_overridden" in dictionary.keys()\
                else APIHelper.SKIP
        plan =\
            PlanDetails.from_dictionary(
                dictionary.get("plan"))\
                if "plan" in dictionary.keys()\
                else APIHelper.SKIP
        links = None
        if dictionary.get("links") is not None:
            links = [
                LinkDescription.from_dictionary(x)
                    for x in dictionary.get("links")
            ]
        else:
            links = APIHelper.SKIP

        # Return an object of this model
        return cls(id,
                   plan_id,
                   start_time,
                   quantity,
                   shipping_amount,
                   subscriber,
                   billing_info,
                   create_time,
                   update_time,
                   custom_id,
                   plan_overridden,
                   plan,
                   links)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _plan_id=(
            self.plan_id
            if hasattr(self, "plan_id")
            else None
        )
        _start_time=(
            self.start_time
            if hasattr(self, "start_time")
            else None
        )
        _quantity=(
            self.quantity
            if hasattr(self, "quantity")
            else None
        )
        _shipping_amount=(
            self.shipping_amount
            if hasattr(self, "shipping_amount")
            else None
        )
        _subscriber=(
            self.subscriber
            if hasattr(self, "subscriber")
            else None
        )
        _billing_info=(
            self.billing_info
            if hasattr(self, "billing_info")
            else None
        )
        _create_time=(
            self.create_time
            if hasattr(self, "create_time")
            else None
        )
        _update_time=(
            self.update_time
            if hasattr(self, "update_time")
            else None
        )
        _custom_id=(
            self.custom_id
            if hasattr(self, "custom_id")
            else None
        )
        _plan_overridden=(
            self.plan_overridden
            if hasattr(self, "plan_overridden")
            else None
        )
        _plan=(
            self.plan
            if hasattr(self, "plan")
            else None
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"plan_id={_plan_id!r}, "
            f"start_time={_start_time!r}, "
            f"quantity={_quantity!r}, "
            f"shipping_amount={_shipping_amount!r}, "
            f"subscriber={_subscriber!r}, "
            f"billing_info={_billing_info!r}, "
            f"create_time={_create_time!r}, "
            f"update_time={_update_time!r}, "
            f"custom_id={_custom_id!r}, "
            f"plan_overridden={_plan_overridden!r}, "
            f"plan={_plan!r}, "
            f"links={_links!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _plan_id=(
            self.plan_id
            if hasattr(self, "plan_id")
            else None
        )
        _start_time=(
            self.start_time
            if hasattr(self, "start_time")
            else None
        )
        _quantity=(
            self.quantity
            if hasattr(self, "quantity")
            else None
        )
        _shipping_amount=(
            self.shipping_amount
            if hasattr(self, "shipping_amount")
            else None
        )
        _subscriber=(
            self.subscriber
            if hasattr(self, "subscriber")
            else None
        )
        _billing_info=(
            self.billing_info
            if hasattr(self, "billing_info")
            else None
        )
        _create_time=(
            self.create_time
            if hasattr(self, "create_time")
            else None
        )
        _update_time=(
            self.update_time
            if hasattr(self, "update_time")
            else None
        )
        _custom_id=(
            self.custom_id
            if hasattr(self, "custom_id")
            else None
        )
        _plan_overridden=(
            self.plan_overridden
            if hasattr(self, "plan_overridden")
            else None
        )
        _plan=(
            self.plan
            if hasattr(self, "plan")
            else None
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"plan_id={_plan_id!s}, "
            f"start_time={_start_time!s}, "
            f"quantity={_quantity!s}, "
            f"shipping_amount={_shipping_amount!s}, "
            f"subscriber={_subscriber!s}, "
            f"billing_info={_billing_info!s}, "
            f"create_time={_create_time!s}, "
            f"update_time={_update_time!s}, "
            f"custom_id={_custom_id!s}, "
            f"plan_overridden={_plan_overridden!s}, "
            f"plan={_plan!s}, "
            f"links={_links!s}, "
            f")"
        )
