# 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 .v1alpha2_allocation_result import V1alpha2AllocationResult
from .v1alpha2_resource_claim_consumer_reference import V1alpha2ResourceClaimConsumerReference

class V1alpha2ResourceClaimStatus(BaseModel):
    """
    ResourceClaimStatus tracks whether the resource has been allocated and what the resulting attributes are.  # noqa: E501
    """
    allocation: Optional[V1alpha2AllocationResult] = None
    deallocation_requested: Optional[StrictBool] = Field(None, alias="deallocationRequested", description="DeallocationRequested indicates that a ResourceClaim is to be deallocated.  The driver then must deallocate this claim and reset the field together with clearing the Allocation field.  While DeallocationRequested is set, no new consumers may be added to ReservedFor.")
    driver_name: Optional[StrictStr] = Field(None, alias="driverName", description="DriverName is a copy of the driver name from the ResourceClass at the time when allocation started.")
    reserved_for: Optional[conlist(V1alpha2ResourceClaimConsumerReference)] = Field(None, alias="reservedFor", description="ReservedFor indicates which entities are currently allowed to use the claim. A Pod which references a ResourceClaim which is not reserved for that Pod will not be started.  There can be at most 32 such reservations. This may get increased in the future, but not reduced.")
    __properties = ["allocation", "deallocationRequested", "driverName", "reservedFor"]

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

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

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

        _obj = V1alpha2ResourceClaimStatus.parse_obj({
            "allocation": V1alpha2AllocationResult.from_dict(obj.get("allocation")) if obj.get("allocation") is not None else None,
            "deallocation_requested": obj.get("deallocationRequested"),
            "driver_name": obj.get("driverName"),
            "reserved_for": [V1alpha2ResourceClaimConsumerReference.from_dict(_item) for _item in obj.get("reservedFor")] if obj.get("reservedFor") is not None else None
        })
        return _obj


