"""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.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 BillingPlan(object):
    """Implementation of the 'Billing Plan' model.

    The plan details.

    Attributes:
        id (str): The unique PayPal-generated ID for the plan.
        product_id (str): The ID for the product.
        name (str): The plan name.
        status (SubscriptionPlanStatus): The plan status.
        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_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.
        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",
        "product_id": "product_id",
        "name": "name",
        "status": "status",
        "description": "description",
        "billing_cycles": "billing_cycles",
        "payment_preferences": "payment_preferences",
        "merchant_preferences": "merchant_preferences",
        "taxes": "taxes",
        "quantity_supported": "quantity_supported",
        "create_time": "create_time",
        "update_time": "update_time",
        "links": "links",
    }

    _optionals = [
        "id",
        "product_id",
        "name",
        "status",
        "description",
        "billing_cycles",
        "payment_preferences",
        "merchant_preferences",
        "taxes",
        "quantity_supported",
        "create_time",
        "update_time",
        "links",
    ]

    def __init__(
        self,
        id=APIHelper.SKIP,
        product_id=APIHelper.SKIP,
        name=APIHelper.SKIP,
        status=APIHelper.SKIP,
        description=APIHelper.SKIP,
        billing_cycles=APIHelper.SKIP,
        payment_preferences=APIHelper.SKIP,
        merchant_preferences=APIHelper.SKIP,
        taxes=APIHelper.SKIP,
        quantity_supported=False,
        create_time=APIHelper.SKIP,
        update_time=APIHelper.SKIP,
        links=APIHelper.SKIP):
        """Initialize a BillingPlan instance."""
        # Initialize members of the class
        if id is not APIHelper.SKIP:
            self.id = id
        if product_id is not APIHelper.SKIP:
            self.product_id = product_id
        if name is not APIHelper.SKIP:
            self.name = name
        if status is not APIHelper.SKIP:
            self.status = status
        if description is not APIHelper.SKIP:
            self.description = description
        if billing_cycles is not APIHelper.SKIP:
            self.billing_cycles = billing_cycles
        if payment_preferences is not APIHelper.SKIP:
            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
        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 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
        product_id =\
            dictionary.get("product_id")\
            if dictionary.get("product_id")\
                else APIHelper.SKIP
        name =\
            dictionary.get("name")\
            if dictionary.get("name")\
                else APIHelper.SKIP
        status =\
            dictionary.get("status")\
            if dictionary.get("status")\
                else APIHelper.SKIP
        description =\
            dictionary.get("description")\
            if dictionary.get("description")\
                else APIHelper.SKIP
        billing_cycles = None
        if dictionary.get("billing_cycles") is not None:
            billing_cycles = [
                SubscriptionBillingCycle.from_dictionary(x)
                    for x in dictionary.get("billing_cycles")
            ]
        else:
            billing_cycles = APIHelper.SKIP
        payment_preferences =\
            PaymentPreferences.from_dictionary(
                dictionary.get("payment_preferences"))\
                if "payment_preferences" in dictionary.keys()\
                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
        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
        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,
                   product_id,
                   name,
                   status,
                   description,
                   billing_cycles,
                   payment_preferences,
                   merchant_preferences,
                   taxes,
                   quantity_supported,
                   create_time,
                   update_time,
                   links)

    def __repr__(self):
        """Return a unambiguous string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _product_id=(
            self.product_id
            if hasattr(self, "product_id")
            else None
        )
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _status=(
            self.status
            if hasattr(self, "status")
            else None
        )
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        _billing_cycles=(
            self.billing_cycles
            if hasattr(self, "billing_cycles")
            else None
        )
        _payment_preferences=(
            self.payment_preferences
            if hasattr(self, "payment_preferences")
            else None
        )
        _merchant_preferences=(
            self.merchant_preferences
            if hasattr(self, "merchant_preferences")
            else None
        )
        _taxes=(
            self.taxes
            if hasattr(self, "taxes")
            else None
        )
        _quantity_supported=(
            self.quantity_supported
            if hasattr(self, "quantity_supported")
            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
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!r}, "
            f"product_id={_product_id!r}, "
            f"name={_name!r}, "
            f"status={_status!r}, "
            f"description={_description!r}, "
            f"billing_cycles={_billing_cycles!r}, "
            f"payment_preferences={_payment_preferences!r}, "
            f"merchant_preferences={_merchant_preferences!r}, "
            f"taxes={_taxes!r}, "
            f"quantity_supported={_quantity_supported!r}, "
            f"create_time={_create_time!r}, "
            f"update_time={_update_time!r}, "
            f"links={_links!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _id=(
            self.id
            if hasattr(self, "id")
            else None
        )
        _product_id=(
            self.product_id
            if hasattr(self, "product_id")
            else None
        )
        _name=(
            self.name
            if hasattr(self, "name")
            else None
        )
        _status=(
            self.status
            if hasattr(self, "status")
            else None
        )
        _description=(
            self.description
            if hasattr(self, "description")
            else None
        )
        _billing_cycles=(
            self.billing_cycles
            if hasattr(self, "billing_cycles")
            else None
        )
        _payment_preferences=(
            self.payment_preferences
            if hasattr(self, "payment_preferences")
            else None
        )
        _merchant_preferences=(
            self.merchant_preferences
            if hasattr(self, "merchant_preferences")
            else None
        )
        _taxes=(
            self.taxes
            if hasattr(self, "taxes")
            else None
        )
        _quantity_supported=(
            self.quantity_supported
            if hasattr(self, "quantity_supported")
            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
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"id={_id!s}, "
            f"product_id={_product_id!s}, "
            f"name={_name!s}, "
            f"status={_status!s}, "
            f"description={_description!s}, "
            f"billing_cycles={_billing_cycles!s}, "
            f"payment_preferences={_payment_preferences!s}, "
            f"merchant_preferences={_merchant_preferences!s}, "
            f"taxes={_taxes!s}, "
            f"quantity_supported={_quantity_supported!s}, "
            f"create_time={_create_time!s}, "
            f"update_time={_update_time!s}, "
            f"links={_links!s}, "
            f")"
        )
