# coding: utf-8

"""
    Kubernetes

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: release-1.29
    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 typing import List, Optional
from pydantic import BaseModel, Field, StrictBool, StrictStr, conlist
from .v1_custom_resource_conversion import V1CustomResourceConversion
from .v1_custom_resource_definition_names import V1CustomResourceDefinitionNames
from .v1_custom_resource_definition_version import V1CustomResourceDefinitionVersion

class V1CustomResourceDefinitionSpec(BaseModel):
    """
    CustomResourceDefinitionSpec describes how a user wants their resource to appear  # noqa: E501
    """
    conversion: Optional[V1CustomResourceConversion] = None
    group: StrictStr = Field(..., description="group is the API group of the defined custom resource. The custom resources are served under `/apis/<group>/...`. Must match the name of the CustomResourceDefinition (in the form `<names.plural>.<group>`).")
    names: V1CustomResourceDefinitionNames = Field(...)
    preserve_unknown_fields: Optional[StrictBool] = Field(None, alias="preserveUnknownFields", description="preserveUnknownFields indicates that object fields which are not specified in the OpenAPI schema should be preserved when persisting to storage. apiVersion, kind, metadata and known fields inside metadata are always preserved. This field is deprecated in favor of setting `x-preserve-unknown-fields` to true in `spec.versions[*].schema.openAPIV3Schema`. See https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-pruning for details.")
    scope: StrictStr = Field(..., description="scope indicates whether the defined custom resource is cluster- or namespace-scoped. Allowed values are `Cluster` and `Namespaced`.")
    versions: conlist(V1CustomResourceDefinitionVersion) = Field(..., description="versions is the list of all API versions of the defined custom resource. Version names are used to compute the order in which served versions are listed in API discovery. If the version string is \"kube-like\", it will sort above non \"kube-like\" version strings, which are ordered lexicographically. \"Kube-like\" versions start with a \"v\", then are followed by a number (the major version), then optionally the string \"alpha\" or \"beta\" and another number (the minor version). These are sorted first by GA > beta > alpha (where GA is a version with no suffix such as beta or alpha), and then by comparing major version, then minor version. An example sorted list of versions: v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10.")
    __properties = ["conversion", "group", "names", "preserveUnknownFields", "scope", "versions"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of conversion
        if self.conversion:
            _dict['conversion'] = self.conversion.to_dict()
        # override the default output from pydantic by calling `to_dict()` of names
        if self.names:
            _dict['names'] = self.names.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in versions (list)
        _items = []
        if self.versions:
            for _item in self.versions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['versions'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> V1CustomResourceDefinitionSpec:
        """Create an instance of V1CustomResourceDefinitionSpec from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return V1CustomResourceDefinitionSpec.parse_obj(obj)

        _obj = V1CustomResourceDefinitionSpec.parse_obj({
            "conversion": V1CustomResourceConversion.from_dict(obj.get("conversion")) if obj.get("conversion") is not None else None,
            "group": obj.get("group"),
            "names": V1CustomResourceDefinitionNames.from_dict(obj.get("names")) if obj.get("names") is not None else None,
            "preserve_unknown_fields": obj.get("preserveUnknownFields"),
            "scope": obj.get("scope"),
            "versions": [V1CustomResourceDefinitionVersion.from_dict(_item) for _item in obj.get("versions")] if obj.get("versions") is not None else None
        })
        return _obj


