# -*- 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.billing_plan import BillingPlan
from paypalserversdk.models.link_description import LinkDescription


class PlanCollection(object):

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

    The list of plans with details.

    Attributes:
        plans (List[BillingPlan]): An array of plans.
        total_items (int): The total number of items.
        total_pages (int): The total number of pages.
        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 = {
        "plans": 'plans',
        "total_items": 'total_items',
        "total_pages": 'total_pages',
        "links": 'links'
    }

    _optionals = [
        'plans',
        'total_items',
        'total_pages',
        'links',
    ]

    def __init__(self,
                 plans=APIHelper.SKIP,
                 total_items=APIHelper.SKIP,
                 total_pages=APIHelper.SKIP,
                 links=APIHelper.SKIP):
        """Constructor for the PlanCollection class"""

        # Initialize members of the class
        if plans is not APIHelper.SKIP:
            self.plans = plans 
        if total_items is not APIHelper.SKIP:
            self.total_items = total_items 
        if total_pages is not APIHelper.SKIP:
            self.total_pages = total_pages 
        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
        plans = None
        if dictionary.get('plans') is not None:
            plans = [BillingPlan.from_dictionary(x) for x in dictionary.get('plans')]
        else:
            plans = APIHelper.SKIP
        total_items = dictionary.get("total_items") if dictionary.get("total_items") else APIHelper.SKIP
        total_pages = dictionary.get("total_pages") if dictionary.get("total_pages") 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(plans,
                   total_items,
                   total_pages,
                   links)

    def __repr__(self):
        return (f'{self.__class__.__name__}('
                f'plans={(self.plans if hasattr(self, "plans") else None)!r}, '
                f'total_items={(self.total_items if hasattr(self, "total_items") else None)!r}, '
                f'total_pages={(self.total_pages if hasattr(self, "total_pages") else None)!r}, '
                f'links={(self.links if hasattr(self, "links") else None)!r})')

    def __str__(self):
        return (f'{self.__class__.__name__}('
                f'plans={(self.plans if hasattr(self, "plans") else None)!s}, '
                f'total_items={(self.total_items if hasattr(self, "total_items") else None)!s}, '
                f'total_pages={(self.total_pages if hasattr(self, "total_pages") else None)!s}, '
                f'links={(self.links if hasattr(self, "links") else None)!s})')
