# 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.37
    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 collections.abc import Mapping as _Mapping
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, cast as _cast
from kubernetes.client.models.v1_modify_volume_status import V1ModifyVolumeStatus
from kubernetes.client.models.v1_persistent_volume_claim_condition import V1PersistentVolumeClaimCondition
from kubernetes.client.models.v1_volume_health_status import V1VolumeHealthStatus
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python


_OPENAPI_GENERATOR_TO_DICT = "_openapi_generator_to_dict"


def _get_openapi_to_dict(value: Any) -> Any:
    # Reciprocal function references preserve inherited generated methods
    # without reserving model member names. Checking both directions also
    # rejects overrides whose decorators copy function attributes.
    to_dict = getattr(value, "to_dict", None)
    type_to_dict = getattr(type(value), "to_dict", None)
    if (
        not callable(to_dict)
        or getattr(to_dict, "__func__", None) is not type_to_dict
    ):
        return None

    openapi_to_dict = getattr(
        type_to_dict, _OPENAPI_GENERATOR_TO_DICT, None
    )
    if (
        not callable(openapi_to_dict)
        or getattr(
            openapi_to_dict,
            _OPENAPI_GENERATOR_TO_DICT,
            None,
        ) is not type_to_dict
    ):
        return None
    return openapi_to_dict


def _to_legacy_item(value: Any, serialize: bool) -> Any:
    to_dict = getattr(value, "to_dict", None)
    if _get_openapi_to_dict(value) is not None and callable(to_dict):
        return to_dict(serialize=serialize)
    if callable(to_dict):
        return to_dict()
    return value


def _to_legacy_value(value: Any, serialize: bool) -> Any:
    # python-legacy converted only immediate list elements or dictionary values:
    # https://github.com/OpenAPITools/openapi-generator/blob/c84b949df1a9ec04ba75989cb49b45c940c2f694/modules/openapi-generator/src/main/resources/python-legacy/model.mustache#L203-L231
    if isinstance(value, list):
        return [_to_legacy_item(item, serialize) for item in value]
    if isinstance(value, dict):
        return {
            key: _to_legacy_item(item, serialize)
            for key, item in value.items()
        }
    return _to_legacy_item(value, serialize)


def _to_openapi_value(value: Any) -> Any:
    if isinstance(value, list):
        return [_to_openapi_value(item) for item in value]
    if isinstance(value, dict):
        return {key: _to_openapi_value(item) for key, item in value.items()}

    to_openapi_dict = _get_openapi_to_dict(value)
    if to_openapi_dict is not None:
        return to_openapi_dict(value)

    to_dict = getattr(value, "to_dict", None)
    if callable(to_dict):
        return to_dict()
    return value


class V1PersistentVolumeClaimStatus(BaseModel):
    """
    PersistentVolumeClaimStatus is the current status of a persistent volume claim.

    Attributes:
      openapi_types (dict): The key is attribute name
                            and the value is attribute type.
      attribute_map (dict): The key is attribute name
                            and the value is json key in definition.
    """ # noqa: E501
    access_modes: Optional[List[StrictStr]] = Field(default=None, validation_alias=AliasChoices("accessModes", "access_modes"), serialization_alias="accessModes", description="accessModes contains the actual access modes the volume backing the PVC has. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1")
    allocated_resource_statuses: Optional[Dict[str, StrictStr]] = Field(default=None, validation_alias=AliasChoices("allocatedResourceStatuses", "allocated_resource_statuses"), serialization_alias="allocatedResourceStatuses", description="allocatedResourceStatuses stores status of resource being resized for the given PVC. Key names follow standard Kubernetes label syntax. Valid values are either:  * Un-prefixed keys:   - storage - the capacity of the volume.  * Custom resources must use implementation-defined prefixed names such as \"example.com/my-custom-resource\" Apart from above values - keys that are unprefixed or have kubernetes.io prefix are considered reserved and hence may not be used.  ClaimResourceStatus can be in any of following states:  - ControllerResizeInProgress:   State set when resize controller starts resizing the volume in control-plane.  - ControllerResizeFailed:   State set when resize has failed in resize controller with a terminal error.  - NodeResizePending:   State set when resize controller has finished resizing the volume but further resizing of   volume is needed on the node.  - NodeResizeInProgress:   State set when kubelet starts resizing the volume.  - NodeResizeFailed:   State set when resizing has failed in kubelet with a terminal error. Transient errors don't set   NodeResizeFailed. For example: if expanding a PVC for more capacity - this field can be one of the following states:  - pvc.status.allocatedResourceStatus['storage'] = \"ControllerResizeInProgress\"      - pvc.status.allocatedResourceStatus['storage'] = \"ControllerResizeFailed\"      - pvc.status.allocatedResourceStatus['storage'] = \"NodeResizePending\"      - pvc.status.allocatedResourceStatus['storage'] = \"NodeResizeInProgress\"      - pvc.status.allocatedResourceStatus['storage'] = \"NodeResizeFailed\" When this field is not set, it means that no resize operation is in progress for the given PVC.  A controller that receives PVC update with previously unknown resourceName or ClaimResourceStatus should ignore the update for the purpose it was designed. For example - a controller that only is responsible for resizing capacity of the volume, should ignore PVC updates that change other valid resources associated with PVC.")
    allocated_resources: Optional[Dict[str, StrictStr]] = Field(default=None, validation_alias=AliasChoices("allocatedResources", "allocated_resources"), serialization_alias="allocatedResources", description="allocatedResources tracks the resources allocated to a PVC including its capacity. Key names follow standard Kubernetes label syntax. Valid values are either:  * Un-prefixed keys:   - storage - the capacity of the volume.  * Custom resources must use implementation-defined prefixed names such as \"example.com/my-custom-resource\" Apart from above values - keys that are unprefixed or have kubernetes.io prefix are considered reserved and hence may not be used.  Capacity reported here may be larger than the actual capacity when a volume expansion operation is requested. For storage quota, the larger value from allocatedResources and PVC.spec.resources is used. If allocatedResources is not set, PVC.spec.resources alone is used for quota calculation. If a volume expansion capacity request is lowered, allocatedResources is only lowered if there are no expansion operations in progress and if the actual volume capacity is equal or lower than the requested capacity.  A controller that receives PVC update with previously unknown resourceName should ignore the update for the purpose it was designed. For example - a controller that only is responsible for resizing capacity of the volume, should ignore PVC updates that change other valid resources associated with PVC.")
    capacity: Optional[Dict[str, StrictStr]] = Field(default=None, description="capacity represents the actual resources of the underlying volume.")
    conditions: Optional[List[V1PersistentVolumeClaimCondition]] = Field(default=None, description="conditions is the current Condition of persistent volume claim. If underlying persistent volume is being resized then the Condition will be set to 'Resizing'.")
    current_volume_attributes_class_name: Optional[StrictStr] = Field(default=None, validation_alias=AliasChoices("currentVolumeAttributesClassName", "current_volume_attributes_class_name"), serialization_alias="currentVolumeAttributesClassName", description="currentVolumeAttributesClassName is the current name of the VolumeAttributesClass the PVC is using. When unset, there is no VolumeAttributeClass applied to this PersistentVolumeClaim")
    health_status: Optional[V1VolumeHealthStatus] = Field(default=None, validation_alias=AliasChoices("healthStatus", "health_status"), serialization_alias="healthStatus")
    modify_volume_status: Optional[V1ModifyVolumeStatus] = Field(default=None, validation_alias=AliasChoices("modifyVolumeStatus", "modify_volume_status"), serialization_alias="modifyVolumeStatus")
    phase: Optional[StrictStr] = Field(default=None, description="phase represents the current phase of PersistentVolumeClaim.")
    openapi_types: ClassVar[Dict[str, str]] = {
        "access_modes": "List[str]",
        "allocated_resource_statuses": "Dict[str, str]",
        "allocated_resources": "Dict[str, str]",
        "capacity": "Dict[str, str]",
        "conditions": "List[V1PersistentVolumeClaimCondition]",
        "current_volume_attributes_class_name": "str",
        "health_status": "V1VolumeHealthStatus",
        "modify_volume_status": "V1ModifyVolumeStatus",
        "phase": "str"
    }

    attribute_map: ClassVar[Dict[str, str]] = {
        "access_modes": "accessModes",
        "allocated_resource_statuses": "allocatedResourceStatuses",
        "allocated_resources": "allocatedResources",
        "capacity": "capacity",
        "conditions": "conditions",
        "current_volume_attributes_class_name": "currentVolumeAttributesClassName",
        "health_status": "healthStatus",
        "modify_volume_status": "modifyVolumeStatus",
        "phase": "phase"
    }
    __properties: ClassVar[List[str]] = ["accessModes", "allocatedResourceStatuses", "allocatedResources", "capacity", "conditions", "currentVolumeAttributesClassName", "healthStatus", "modifyVolumeStatus", "phase"]

    @classmethod
    def __preprocess_input_names(
        cls,
        obj: Any,
        remove_hidden_storage_names: bool = True,
    ) -> Any:
        if not isinstance(obj, _Mapping):
            return obj
        obj = dict(obj)
        if "accessModes" not in obj and "access_modes" in obj:
            obj["accessModes"] = obj["access_modes"]
        obj.pop("access_modes", None)
        if "allocatedResourceStatuses" not in obj and "allocated_resource_statuses" in obj:
            obj["allocatedResourceStatuses"] = obj["allocated_resource_statuses"]
        obj.pop("allocated_resource_statuses", None)
        if "allocatedResources" not in obj and "allocated_resources" in obj:
            obj["allocatedResources"] = obj["allocated_resources"]
        obj.pop("allocated_resources", None)
        if "currentVolumeAttributesClassName" not in obj and "current_volume_attributes_class_name" in obj:
            obj["currentVolumeAttributesClassName"] = obj["current_volume_attributes_class_name"]
        obj.pop("current_volume_attributes_class_name", None)
        if "healthStatus" not in obj and "health_status" in obj:
            obj["healthStatus"] = obj["health_status"]
        obj.pop("health_status", None)
        if "modifyVolumeStatus" not in obj and "modify_volume_status" in obj:
            obj["modifyVolumeStatus"] = obj["modify_volume_status"]
        obj.pop("modify_volume_status", None)
        return obj

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=True,
        validate_assignment=True,
        extra="forbid",
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model"""
        return pprint.pformat(self.to_dict())

    def __repr__(self) -> str:
        """For print and pprint"""
        return self.to_str()

    def __eq__(self, other: object) -> bool:
        """Returns true if both objects are equal"""
        if not isinstance(other, V1PersistentVolumeClaimStatus):
            return False

        return self.to_dict() == other.to_dict()

    def __ne__(self, other: object) -> bool:
        """Returns true if both objects are not equal"""
        if not isinstance(other, V1PersistentVolumeClaimStatus):
            return True

        return not (self == other)


    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        to_openapi_dict = _get_openapi_to_dict(self)
        if to_openapi_dict is not None:
            return json.dumps(to_jsonable_python(to_openapi_dict(self)))
        return json.dumps(to_jsonable_python(self.to_dict()))

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

    def to_dict(self, serialize: bool = False) -> Dict[str, Any]:
        """Return all declared model fields using public or wire names."""
        return {
            ("accessModes" if serialize else "access_modes"): _to_legacy_value(getattr(self, "access_modes", None), serialize),
            ("allocatedResourceStatuses" if serialize else "allocated_resource_statuses"): _to_legacy_value(getattr(self, "allocated_resource_statuses", None), serialize),
            ("allocatedResources" if serialize else "allocated_resources"): _to_legacy_value(getattr(self, "allocated_resources", None), serialize),
            ("capacity" if serialize else "capacity"): _to_legacy_value(getattr(self, "capacity", None), serialize),
            ("conditions" if serialize else "conditions"): _to_legacy_value(getattr(self, "conditions", None), serialize),
            ("currentVolumeAttributesClassName" if serialize else "current_volume_attributes_class_name"): _to_legacy_value(getattr(self, "current_volume_attributes_class_name", None), serialize),
            ("healthStatus" if serialize else "health_status"): _to_legacy_value(getattr(self, "health_status", None), serialize),
            ("modifyVolumeStatus" if serialize else "modify_volume_status"): _to_legacy_value(getattr(self, "modify_volume_status", None), serialize),
            ("phase" if serialize else "phase"): _to_legacy_value(getattr(self, "phase", None), serialize),
        }

    def __openapi_generator_modern_projection(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.
        """
        excluded_fields: Set[str] = set([
        ])

        _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 conditions (list)
        _items = []
        if self.conditions:
            for _item_conditions in self.conditions:
                _items.append(_to_openapi_value(_item_conditions) if _item_conditions is not None else None)
            _dict['conditions'] = _items
        # override the default output from pydantic by calling `to_dict()` of health_status
        if self.health_status:
            _dict['healthStatus'] = _to_openapi_value(self.health_status)
        # override the default output from pydantic by calling `to_dict()` of modify_volume_status
        if self.modify_volume_status:
            _dict['modifyVolumeStatus'] = _to_openapi_value(self.modify_volume_status)
        return _dict

    setattr(
        to_dict,
        _OPENAPI_GENERATOR_TO_DICT,
        __openapi_generator_modern_projection,
    )
    setattr(
        __openapi_generator_modern_projection,
        _OPENAPI_GENERATOR_TO_DICT,
        to_dict,
    )
    del __openapi_generator_modern_projection

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

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

        obj = _cast(
            Dict[str, Any],
            cls.__preprocess_input_names(
                obj,
                remove_hidden_storage_names=True,
            ),
        )

        _obj = cls.model_validate({
            "accessModes": obj.get("accessModes"),
            "allocatedResourceStatuses": obj.get("allocatedResourceStatuses"),
            "allocatedResources": obj.get("allocatedResources"),
            "capacity": obj.get("capacity"),
            "conditions": [V1PersistentVolumeClaimCondition.from_dict(_item) for _item in obj["conditions"]] if obj.get("conditions") is not None else None,
            "currentVolumeAttributesClassName": obj.get("currentVolumeAttributesClassName"),
            "healthStatus": V1VolumeHealthStatus.from_dict(obj["healthStatus"]) if obj.get("healthStatus") is not None else None,
            "modifyVolumeStatus": V1ModifyVolumeStatus.from_dict(obj["modifyVolumeStatus"]) if obj.get("modifyVolumeStatus") is not None else None,
            "phase": obj.get("phase")
        })
        return _obj
