# 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, StrictStr, conlist
from .v1alpha1_server_storage_version import V1alpha1ServerStorageVersion
from .v1alpha1_storage_version_condition import V1alpha1StorageVersionCondition

class V1alpha1StorageVersionStatus(BaseModel):
    """
    API server instances report the versions they can decode and the version they encode objects to when persisting objects in the backend.  # noqa: E501
    """
    common_encoding_version: Optional[StrictStr] = Field(None, alias="commonEncodingVersion", description="If all API server instances agree on the same encoding storage version, then this field is set to that version. Otherwise this field is left empty. API servers should finish updating its storageVersionStatus entry before serving write operations, so that this field will be in sync with the reality.")
    conditions: Optional[conlist(V1alpha1StorageVersionCondition)] = Field(None, description="The latest available observations of the storageVersion's state.")
    storage_versions: Optional[conlist(V1alpha1ServerStorageVersion)] = Field(None, alias="storageVersions", description="The reported versions per API server instance.")
    __properties = ["commonEncodingVersion", "conditions", "storageVersions"]

    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) -> V1alpha1StorageVersionStatus:
        """Create an instance of V1alpha1StorageVersionStatus 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 each item in conditions (list)
        _items = []
        if self.conditions:
            for _item in self.conditions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['conditions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in storage_versions (list)
        _items = []
        if self.storage_versions:
            for _item in self.storage_versions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['storageVersions'] = _items
        return _dict

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

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

        _obj = V1alpha1StorageVersionStatus.parse_obj({
            "common_encoding_version": obj.get("commonEncodingVersion"),
            "conditions": [V1alpha1StorageVersionCondition.from_dict(_item) for _item in obj.get("conditions")] if obj.get("conditions") is not None else None,
            "storage_versions": [V1alpha1ServerStorageVersion.from_dict(_item) for _item in obj.get("storageVersions")] if obj.get("storageVersions") is not None else None
        })
        return _obj


