# -*- 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.merchant_preferences import MerchantPreferences
from paypalserversdk.models.payment_preferences import PaymentPreferences
from paypalserversdk.models.subscription_billing_cycle import SubscriptionBillingCycle
from paypalserversdk.models.taxes import Taxes


class PlanRequest(object):

    """Implementation of the 'Plan Request' model.

    The create plan request details.

    Attributes:
        product_id (str): The ID of the product created through Catalog
            Products API.
        name (str): The plan name.
        status (PlanRequestStatus): The initial state of the plan. Allowed
            input values are CREATED and ACTIVE.
        description (str): The detailed description of the plan.
        billing_cycles (List[SubscriptionBillingCycle]): An array of billing
            cycles for trial billing and regular billing. A plan can have at
            most two trial cycles and only one regular cycle.
        payment_preferences (PaymentPreferences): The payment preferences for
            a subscription.
        merchant_preferences (MerchantPreferences): The merchant preferences
            for a subscription.
        taxes (Taxes): The tax details.
        quantity_supported (bool): Indicates whether you can subscribe to this
            plan by providing a quantity for the goods or service.

    """

    # Create a mapping from Model property names to API property names
    _names = {
        "product_id": 'product_id',
        "name": 'name',
        "billing_cycles": 'billing_cycles',
        "payment_preferences": 'payment_preferences',
        "status": 'status',
        "description": 'description',
        "merchant_preferences": 'merchant_preferences',
        "taxes": 'taxes',
        "quantity_supported": 'quantity_supported'
    }

    _optionals = [
        'status',
        'description',
        'merchant_preferences',
        'taxes',
        'quantity_supported',
    ]

    def __init__(self,
                 product_id=None,
                 name=None,
                 billing_cycles=None,
                 payment_preferences=None,
                 status='ACTIVE',
                 description=APIHelper.SKIP,
                 merchant_preferences=APIHelper.SKIP,
                 taxes=APIHelper.SKIP,
                 quantity_supported=False):
        """Constructor for the PlanRequest class"""

        # Initialize members of the class
        self.product_id = product_id 
        self.name = name 
        self.status = status 
        if description is not APIHelper.SKIP:
            self.description = description 
        self.billing_cycles = billing_cycles 
        self.payment_preferences = payment_preferences 
        if merchant_preferences is not APIHelper.SKIP:
            self.merchant_preferences = merchant_preferences 
        if taxes is not APIHelper.SKIP:
            self.taxes = taxes 
        self.quantity_supported = quantity_supported 

    @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
        product_id = dictionary.get("product_id") if dictionary.get("product_id") else None
        name = dictionary.get("name") if dictionary.get("name") else None
        billing_cycles = None
        if dictionary.get('billing_cycles') is not None:
            billing_cycles = [SubscriptionBillingCycle.from_dictionary(x) for x in dictionary.get('billing_cycles')]
        payment_preferences = PaymentPreferences.from_dictionary(dictionary.get('payment_preferences')) if dictionary.get('payment_preferences') else None
        status = dictionary.get("status") if dictionary.get("status") else 'ACTIVE'
        description = dictionary.get("description") if dictionary.get("description") else APIHelper.SKIP
        merchant_preferences = MerchantPreferences.from_dictionary(dictionary.get('merchant_preferences')) if 'merchant_preferences' in dictionary.keys() else APIHelper.SKIP
        taxes = Taxes.from_dictionary(dictionary.get('taxes')) if 'taxes' in dictionary.keys() else APIHelper.SKIP
        quantity_supported = dictionary.get("quantity_supported") if dictionary.get("quantity_supported") else False
        # Return an object of this model
        return cls(product_id,
                   name,
                   billing_cycles,
                   payment_preferences,
                   status,
                   description,
                   merchant_preferences,
                   taxes,
                   quantity_supported)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'product_id={self.product_id!r}, '
                f'name={self.name!r}, '
                f'status={(self.status if hasattr(self, "status") else None)!r}, '
                f'description={(self.description if hasattr(self, "description") else None)!r}, '
                f'billing_cycles={self.billing_cycles!r}, '
                f'payment_preferences={self.payment_preferences!r}, '
                f'merchant_preferences={(self.merchant_preferences if hasattr(self, "merchant_preferences") else None)!r}, '
                f'taxes={(self.taxes if hasattr(self, "taxes") else None)!r}, '
                f'quantity_supported={(self.quantity_supported if hasattr(self, "quantity_supported") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'product_id={self.product_id!s}, '
                f'name={self.name!s}, '
                f'status={(self.status if hasattr(self, "status") else None)!s}, '
                f'description={(self.description if hasattr(self, "description") else None)!s}, '
                f'billing_cycles={self.billing_cycles!s}, '
                f'payment_preferences={self.payment_preferences!s}, '
                f'merchant_preferences={(self.merchant_preferences if hasattr(self, "merchant_preferences") else None)!s}, '
                f'taxes={(self.taxes if hasattr(self, "taxes") else None)!s}, '
                f'quantity_supported={(self.quantity_supported if hasattr(self, "quantity_supported") else None)!s})')
