# coding: utf-8

"""
    Data Space Catalog

    The service provides a REST API for managing and sharing catalog data. Interacts with connector services to obtain information about data products.

    The version of the OpenAPI document: 0.1.1
    Contact: all-hiro@hiro-microdatacenters.nl
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List
from ds_catalog.models.data_product import DataProduct
from ds_catalog.models.ontology import Ontology
from ds_catalog.models.user import User
from typing import Optional, Set
from typing_extensions import Self

class CatalogItem(BaseModel):
    """
    CatalogItem
    """ # noqa: E501
    ontology: Ontology
    title: StrictStr
    summary: StrictStr
    id: StrictStr
    is_local: StrictBool = Field(alias="isLocal")
    is_shared: StrictBool = Field(alias="isShared")
    created: datetime
    creator: User
    data_products: List[DataProduct] = Field(alias="dataProducts")
    links: Dict[str, StrictStr] = Field(alias="_links")
    __properties: ClassVar[List[str]] = ["ontology", "title", "summary", "id", "isLocal", "isShared", "created", "creator", "dataProducts", "_links"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of CatalogItem from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of creator
        if self.creator:
            _dict['creator'] = self.creator.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in data_products (list)
        _items = []
        if self.data_products:
            for _item_data_products in self.data_products:
                if _item_data_products:
                    _items.append(_item_data_products.to_dict())
            _dict['dataProducts'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CatalogItem from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "ontology": obj.get("ontology"),
            "title": obj.get("title"),
            "summary": obj.get("summary"),
            "id": obj.get("id"),
            "isLocal": obj.get("isLocal"),
            "isShared": obj.get("isShared"),
            "created": obj.get("created"),
            "creator": User.from_dict(obj["creator"]) if obj.get("creator") is not None else None,
            "dataProducts": [DataProduct.from_dict(_item) for _item in obj["dataProducts"]] if obj.get("dataProducts") is not None else None,
            "_links": obj.get("_links")
        })
        return _obj


