# -*- coding: utf-8 -*-

"""
paypalserversdk

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""
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):
        """Constructor for the Subscription class"""

        # 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):
        """Creates 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 (f'{self.__class__.__name__}('
                f'id={(self.id if hasattr(self, "id") else None)!r}, '
                f'plan_id={(self.plan_id if hasattr(self, "plan_id") else None)!r}, '
                f'start_time={(self.start_time if hasattr(self, "start_time") else None)!r}, '
                f'quantity={(self.quantity if hasattr(self, "quantity") else None)!r}, '
                f'shipping_amount={(self.shipping_amount if hasattr(self, "shipping_amount") else None)!r}, '
                f'subscriber={(self.subscriber if hasattr(self, "subscriber") else None)!r}, '
                f'billing_info={(self.billing_info if hasattr(self, "billing_info") else None)!r}, '
                f'create_time={(self.create_time if hasattr(self, "create_time") else None)!r}, '
                f'update_time={(self.update_time if hasattr(self, "update_time") else None)!r}, '
                f'custom_id={(self.custom_id if hasattr(self, "custom_id") else None)!r}, '
                f'plan_overridden={(self.plan_overridden if hasattr(self, "plan_overridden") else None)!r}, '
                f'plan={(self.plan if hasattr(self, "plan") else None)!r}, '
                f'links={(self.links if hasattr(self, "links") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'id={(self.id if hasattr(self, "id") else None)!s}, '
                f'plan_id={(self.plan_id if hasattr(self, "plan_id") else None)!s}, '
                f'start_time={(self.start_time if hasattr(self, "start_time") else None)!s}, '
                f'quantity={(self.quantity if hasattr(self, "quantity") else None)!s}, '
                f'shipping_amount={(self.shipping_amount if hasattr(self, "shipping_amount") else None)!s}, '
                f'subscriber={(self.subscriber if hasattr(self, "subscriber") else None)!s}, '
                f'billing_info={(self.billing_info if hasattr(self, "billing_info") else None)!s}, '
                f'create_time={(self.create_time if hasattr(self, "create_time") else None)!s}, '
                f'update_time={(self.update_time if hasattr(self, "update_time") else None)!s}, '
                f'custom_id={(self.custom_id if hasattr(self, "custom_id") else None)!s}, '
                f'plan_overridden={(self.plan_overridden if hasattr(self, "plan_overridden") else None)!s}, '
                f'plan={(self.plan if hasattr(self, "plan") else None)!s}, '
                f'links={(self.links if hasattr(self, "links") else None)!s})')
