# 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.artifact_ref_response import ArtifactRefResponse
from pulpcore.client.pulp_ansible.models.collection_metadata_response import CollectionMetadataResponse
from pulpcore.client.pulp_ansible.models.collection_namespace_response import CollectionNamespaceResponse
from pulpcore.client.pulp_ansible.models.collection_ref_response import CollectionRefResponse
from pulpcore.client.pulp_ansible.models.collection_version_signature_response import CollectionVersionSignatureResponse
from typing import Optional, Set
from typing_extensions import Self

class UnpaginatedCollectionVersionResponse(BaseModel):
    """
    A serializer for unpaginated CollectionVersion.
    """ # noqa: E501
    version: Annotated[str, Field(strict=True, max_length=128)]
    href: Optional[StrictStr] = Field(default=None, description="Get href.")
    created_at: datetime
    updated_at: datetime
    requires_ansible: Optional[StrictStr] = None
    marks: Optional[List[StrictStr]] = Field(default=None, description="Get a list of mark values filtering only those in the current repo.")
    artifact: Optional[ArtifactRefResponse] = None
    collection: Optional[CollectionRefResponse] = None
    download_url: Optional[StrictStr] = Field(default=None, description="Get artifact download URL.")
    name: Optional[StrictStr] = None
    namespace: Optional[CollectionNamespaceResponse] = None
    signatures: List[CollectionVersionSignatureResponse]
    metadata: Optional[CollectionMetadataResponse] = None
    git_url: Optional[StrictStr] = Field(default=None, description="Get the git URL.")
    git_commit_sha: Optional[StrictStr] = Field(default=None, description="Get the git commit sha.")
    __properties: ClassVar[List[str]] = ["version", "href", "created_at", "updated_at", "requires_ansible", "marks", "artifact", "collection", "download_url", "name", "namespace", "signatures", "metadata", "git_url", "git_commit_sha"]

    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 UnpaginatedCollectionVersionResponse 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.
        """
        excluded_fields: Set[str] = set([
            "href",
            "artifact",
            "collection",
            "download_url",
            "name",
            "namespace",
            "metadata",
            "git_url",
            "git_commit_sha",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of artifact
        if self.artifact:
            _dict['artifact'] = self.artifact.to_dict()
        # override the default output from pydantic by calling `to_dict()` of collection
        if self.collection:
            _dict['collection'] = self.collection.to_dict()
        # override the default output from pydantic by calling `to_dict()` of namespace
        if self.namespace:
            _dict['namespace'] = self.namespace.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in signatures (list)
        _items = []
        if self.signatures:
            for _item_signatures in self.signatures:
                if _item_signatures:
                    _items.append(_item_signatures.to_dict())
            _dict['signatures'] = _items
        # override the default output from pydantic by calling `to_dict()` of metadata
        if self.metadata:
            _dict['metadata'] = self.metadata.to_dict()
        # 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 UnpaginatedCollectionVersionResponse from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate(obj)
        return _obj


