# 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 Dict, Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
from .v1_container_state import V1ContainerState
from .v1_resource_requirements import V1ResourceRequirements

class V1ContainerStatus(BaseModel):
    """
    ContainerStatus contains details for the current status of this container.  # noqa: E501
    """
    allocated_resources: Optional[Dict[str, StrictStr]] = Field(None, alias="allocatedResources", description="AllocatedResources represents the compute resources allocated for this container by the node. Kubelet sets this value to Container.Resources.Requests upon successful pod admission and after successfully admitting desired pod resize.")
    container_id: Optional[StrictStr] = Field(None, alias="containerID", description="ContainerID is the ID of the container in the format '<type>://<container_id>'. Where type is a container runtime identifier, returned from Version call of CRI API (for example \"containerd\").")
    image: StrictStr = Field(..., description="Image is the name of container image that the container is running. The container image may not match the image used in the PodSpec, as it may have been resolved by the runtime. More info: https://kubernetes.io/docs/concepts/containers/images.")
    image_id: StrictStr = Field(..., alias="imageID", description="ImageID is the image ID of the container's image. The image ID may not match the image ID of the image used in the PodSpec, as it may have been resolved by the runtime.")
    last_state: Optional[V1ContainerState] = Field(None, alias="lastState")
    name: StrictStr = Field(..., description="Name is a DNS_LABEL representing the unique name of the container. Each container in a pod must have a unique name across all container types. Cannot be updated.")
    ready: StrictBool = Field(..., description="Ready specifies whether the container is currently passing its readiness check. The value will change as readiness probes keep executing. If no readiness probes are specified, this field defaults to true once the container is fully started (see Started field).  The value is typically used to determine whether a container is ready to accept traffic.")
    resources: Optional[V1ResourceRequirements] = None
    restart_count: StrictInt = Field(..., alias="restartCount", description="RestartCount holds the number of times the container has been restarted. Kubelet makes an effort to always increment the value, but there are cases when the state may be lost due to node restarts and then the value may be reset to 0. The value is never negative.")
    started: Optional[StrictBool] = Field(None, description="Started indicates whether the container has finished its postStart lifecycle hook and passed its startup probe. Initialized as false, becomes true after startupProbe is considered successful. Resets to false when the container is restarted, or if kubelet loses state temporarily. In both cases, startup probes will run again. Is always true when no startupProbe is defined and container is running and has passed the postStart lifecycle hook. The null value must be treated the same as false.")
    state: Optional[V1ContainerState] = None
    __properties = ["allocatedResources", "containerID", "image", "imageID", "lastState", "name", "ready", "resources", "restartCount", "started", "state"]

    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) -> V1ContainerStatus:
        """Create an instance of V1ContainerStatus 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 last_state
        if self.last_state:
            _dict['lastState'] = self.last_state.to_dict()
        # override the default output from pydantic by calling `to_dict()` of resources
        if self.resources:
            _dict['resources'] = self.resources.to_dict()
        # override the default output from pydantic by calling `to_dict()` of state
        if self.state:
            _dict['state'] = self.state.to_dict()
        return _dict

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

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

        _obj = V1ContainerStatus.parse_obj({
            "allocated_resources": obj.get("allocatedResources"),
            "container_id": obj.get("containerID"),
            "image": obj.get("image"),
            "image_id": obj.get("imageID"),
            "last_state": V1ContainerState.from_dict(obj.get("lastState")) if obj.get("lastState") is not None else None,
            "name": obj.get("name"),
            "ready": obj.get("ready"),
            "resources": V1ResourceRequirements.from_dict(obj.get("resources")) if obj.get("resources") is not None else None,
            "restart_count": obj.get("restartCount"),
            "started": obj.get("started"),
            "state": V1ContainerState.from_dict(obj.get("state")) if obj.get("state") is not None else None
        })
        return _obj


