from typing import Any, Dict, Type, TypeVar, Union

import attr

from ..types import UNSET, Unset

T = TypeVar("T", bound="ResourcesPage")


try:
    from ..models import base_page
except ImportError:
    import sys

    base_page = sys.modules[__package__ + "base_page"]


@attr.s(auto_attribs=True)
class ResourcesPage(base_page.BasePage):
    """ """

    resources: "Union[Unset, List[resource_m.Resource]]" = UNSET

    def to_dict(self) -> Dict[str, Any]:
        resources: Union[Unset, List[Dict[str, Any]]] = UNSET
        if not isinstance(self.resources, Unset):
            resources = []
            for resources_item_data in self.resources:
                resources_item = resources_item_data.to_dict()

                resources.append(resources_item)

        field_dict: Dict[str, Any] = {}
        _BasePage_dict = super().to_dict()
        field_dict.update(_BasePage_dict)
        field_dict.update({})
        if resources is not UNSET:
            field_dict["resources"] = resources

        return field_dict

    @classmethod
    def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:

        try:
            from ..models import resource as resource_m
        except ImportError:
            import sys

            resource_m = sys.modules[__package__ + "resource"]

        d = src_dict.copy()

        resources = []
        _resources = d.pop("resources", UNSET)
        for resources_item_data in _resources or []:
            resources_item = resource_m.Resource.from_dict(resources_item_data)

            resources.append(resources_item)

        resources_page = cls(
            resources=resources,
        )

        return resources_page
