"""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.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):
        """Initialize a PlanCollection instance."""
        # 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):
        """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
        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 a unambiguous string representation."""
        _plans=(
            self.plans
            if hasattr(self, "plans")
            else None
        )
        _total_items=(
            self.total_items
            if hasattr(self, "total_items")
            else None
        )
        _total_pages=(
            self.total_pages
            if hasattr(self, "total_pages")
            else None
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"plans={_plans!r}, "
            f"total_items={_total_items!r}, "
            f"total_pages={_total_pages!r}, "
            f"links={_links!r}, "
            f")"
        )

    def __str__(self):
        """Return a human-readable string representation."""
        _plans=(
            self.plans
            if hasattr(self, "plans")
            else None
        )
        _total_items=(
            self.total_items
            if hasattr(self, "total_items")
            else None
        )
        _total_pages=(
            self.total_pages
            if hasattr(self, "total_pages")
            else None
        )
        _links=(
            self.links
            if hasattr(self, "links")
            else None
        )
        return (
            f"{self.__class__.__name__}("
            f"plans={_plans!s}, "
            f"total_items={_total_items!s}, "
            f"total_pages={_total_pages!s}, "
            f"links={_links!s}, "
            f")"
        )
