# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
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 CollectionResponse(BaseModel):
    """
    A serializer for a Collection.
    """ # noqa: E501
    href: Optional[StrictStr] = Field(default=None, description="Get href.")
    namespace: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    deprecated: StrictBool
    versions_url: Optional[StrictStr] = Field(default=None, description="Get a link to a collection versions list.")
    highest_version: Optional[Dict[str, Any]] = Field(default=None, description="Get a highest version and its link.")
    created_at: Optional[datetime] = Field(default=None, description="Get the timestamp of the lowest version CollectionVersion's created timestamp.")
    updated_at: Optional[datetime] = Field(default=None, description="Get the timestamp of the latest version CollectionVersion's created timestamp.")
    download_count: Optional[StrictInt] = Field(default=None, description="Get the download count of the collection")
    __properties: ClassVar[List[str]] = ["href", "namespace", "name", "deprecated", "versions_url", "highest_version", "created_at", "updated_at", "download_count"]

    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 CollectionResponse 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.
        """
        excluded_fields: Set[str] = set([
            "href",
            "namespace",
            "name",
            "versions_url",
            "highest_version",
            "created_at",
            "updated_at",
            "download_count",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "href": obj.get("href"),
            "namespace": obj.get("namespace"),
            "name": obj.get("name"),
            "deprecated": obj.get("deprecated"),
            "versions_url": obj.get("versions_url"),
            "highest_version": obj.get("highest_version"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "download_count": obj.get("download_count")
        })
        return _obj


