# 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 AnsibleCollectionVersionResponse(BaseModel):
    """
    A serializer for CollectionVersion Content.
    """ # noqa: E501
    prn: Optional[StrictStr] = Field(default=None, description="The Pulp Resource Name (PRN).")
    pulp_labels: Optional[Dict[str, Optional[StrictStr]]] = Field(default=None, description="A dictionary of arbitrary key/value pairs used to describe a specific Content instance.")
    artifact: Optional[StrictStr] = Field(default=None, description="Artifact file representing the physical content")
    pulp_created: Optional[datetime] = Field(default=None, description="Timestamp of creation.")
    pulp_last_updated: Optional[datetime] = Field(default=None, description="Timestamp of the last time this resource was updated. Note: for immutable resources - like content, repository versions, and publication - pulp_created and pulp_last_updated dates will be the same.")
    pulp_href: Optional[StrictStr] = None
    sha256: Optional[StrictStr] = Field(default=None, description="The SHA-256 checksum if available.")
    md5: Optional[StrictStr] = Field(default=None, description="The MD5 checksum if available.")
    sha1: Optional[StrictStr] = Field(default=None, description="The SHA-1 checksum if available.")
    sha224: Optional[StrictStr] = Field(default=None, description="The SHA-224 checksum if available.")
    sha384: Optional[StrictStr] = Field(default=None, description="The SHA-384 checksum if available.")
    sha512: Optional[StrictStr] = Field(default=None, description="The SHA-512 checksum if available.")
    id: Optional[StrictStr] = Field(default=None, description="A collection identifier.")
    authors: Optional[List[Annotated[str, Field(strict=True, max_length=64)]]] = Field(default=None, description="A list of the CollectionVersion content's authors.")
    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.")
    documentation: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = Field(default=None, description="The URL to any online docs.")
    homepage: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = Field(default=None, description="The URL to the homepage of the collection/project.")
    issues: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = Field(default=None, description="The URL to the collection issue tracker.")
    license: Optional[List[Annotated[str, Field(strict=True, max_length=32)]]] = Field(default=None, description="A list of licenses for content inside of a collection.")
    name: Optional[Annotated[str, Field(strict=True, max_length=64)]] = Field(default=None, description="The name of the collection.")
    namespace: Optional[Annotated[str, Field(strict=True, max_length=64)]] = Field(default=None, description="The namespace of the collection.")
    origin_repository: Optional[Annotated[str, Field(strict=True, max_length=2000)]] = Field(default=None, description="The URL of the originating SCM repository.")
    tags: Optional[List[AnsibleTagResponse]] = None
    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.")
    __properties: ClassVar[List[str]] = ["prn", "pulp_labels", "artifact", "pulp_created", "pulp_last_updated", "pulp_href", "sha256", "md5", "sha1", "sha224", "sha384", "sha512", "id", "authors", "dependencies", "description", "documentation", "homepage", "issues", "license", "name", "namespace", "origin_repository", "tags", "version", "requires_ansible"]

    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 AnsibleCollectionVersionResponse 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.
        * 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.
        * 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([
            "prn",
            "pulp_created",
            "pulp_last_updated",
            "pulp_href",
            "sha256",
            "md5",
            "sha1",
            "sha224",
            "sha384",
            "sha512",
            "id",
            "authors",
            "dependencies",
            "description",
            "documentation",
            "homepage",
            "issues",
            "license",
            "name",
            "namespace",
            "origin_repository",
            "tags",
            "version",
            "requires_ansible",
        ])

        _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 AnsibleCollectionVersionResponse from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "prn": obj.get("prn"),
            "pulp_labels": obj.get("pulp_labels"),
            "artifact": obj.get("artifact"),
            "pulp_created": obj.get("pulp_created"),
            "pulp_last_updated": obj.get("pulp_last_updated"),
            "pulp_href": obj.get("pulp_href"),
            "sha256": obj.get("sha256"),
            "md5": obj.get("md5"),
            "sha1": obj.get("sha1"),
            "sha224": obj.get("sha224"),
            "sha384": obj.get("sha384"),
            "sha512": obj.get("sha512"),
            "id": obj.get("id"),
            "authors": obj.get("authors"),
            "dependencies": obj.get("dependencies"),
            "description": obj.get("description"),
            "documentation": obj.get("documentation"),
            "homepage": obj.get("homepage"),
            "issues": obj.get("issues"),
            "license": obj.get("license"),
            "name": obj.get("name"),
            "namespace": obj.get("namespace"),
            "origin_repository": obj.get("origin_repository"),
            "tags": [AnsibleTagResponse.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None,
            "version": obj.get("version"),
            "requires_ansible": obj.get("requires_ansible")
        })
        return _obj


