# coding: utf-8

"""
    Pulp 3 API

    Fetch, Upload, Organize, and Distribute Software Packages

    The version of the OpenAPI document: v3
    Contact: pulp-list@redhat.com
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from pulpcore.client.pulp_ansible.models.ansible_tag_response import AnsibleTagResponse
from typing import Optional, Set
from typing_extensions import Self


class OneOf:
    @staticmethod
    def from_dict(obj, *args, **kwargs):
        """Noop override to fix missing OneOf import/implementation."""
        return obj


class CollectionSummaryResponse(BaseModel):
    """
    Collection Version serializer without docs blob.
    """ # noqa: E501
    pulp_href: Optional[StrictStr] = None
    namespace: Optional[Annotated[str, Field(strict=True, max_length=64)]] = Field(default=None, description="The namespace of the collection.")
    name: Optional[Annotated[str, Field(strict=True, max_length=64)]] = Field(default=None, description="The name of the collection.")
    version: Optional[Annotated[str, Field(strict=True, max_length=128)]] = Field(default=None, description="The version of the collection.")
    requires_ansible: Optional[Annotated[str, Field(strict=True, max_length=255)]] = Field(default=None, description="The version of Ansible required to use the collection. Multiple versions can be separated with a comma.")
    pulp_created: Optional[datetime] = Field(default=None, description="Timestamp of creation.")
    contents: Optional[List[Any]] = Field(default=None, description="A JSON field with data about the contents.")
    dependencies: Optional[Dict[str, Any]] = Field(default=None, description="A dict declaring Collections that this collection requires to be installed for it to be usable.")
    description: Optional[StrictStr] = Field(default=None, description="A short summary description of the collection.")
    tags: Optional[List[AnsibleTagResponse]] = None
    __properties: ClassVar[List[str]] = ["pulp_href", "namespace", "name", "version", "requires_ansible", "pulp_created", "contents", "dependencies", "description", "tags"]

    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 CollectionSummaryResponse 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "pulp_href",
            "namespace",
            "name",
            "version",
            "requires_ansible",
            "pulp_created",
            "contents",
            "dependencies",
            "description",
            "tags",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        # set to None if requires_ansible (nullable) is None
        # and model_fields_set contains the field
        if self.requires_ansible is None and "requires_ansible" in self.model_fields_set:
            _dict['requires_ansible'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "pulp_href": obj.get("pulp_href"),
            "namespace": obj.get("namespace"),
            "name": obj.get("name"),
            "version": obj.get("version"),
            "requires_ansible": obj.get("requires_ansible"),
            "pulp_created": obj.get("pulp_created"),
            "contents": obj.get("contents"),
            "dependencies": obj.get("dependencies"),
            "description": obj.get("description"),
            "tags": [AnsibleTagResponse.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None
        })
        return _obj


