# 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, conlist
from .v1_node_selector import V1NodeSelector
from .v1alpha2_resource_handle import V1alpha2ResourceHandle

class V1alpha2AllocationResult(BaseModel):
    """
    AllocationResult contains attributes of an allocated resource.  # noqa: E501
    """
    available_on_nodes: Optional[V1NodeSelector] = Field(None, alias="availableOnNodes")
    resource_handles: Optional[conlist(V1alpha2ResourceHandle)] = Field(None, alias="resourceHandles", description="ResourceHandles contain the state associated with an allocation that should be maintained throughout the lifetime of a claim. Each ResourceHandle contains data that should be passed to a specific kubelet plugin once it lands on a node. This data is returned by the driver after a successful allocation and is opaque to Kubernetes. Driver documentation may explain to users how to interpret this data if needed.  Setting this field is optional. It has a maximum size of 32 entries. If null (or empty), it is assumed this allocation will be processed by a single kubelet plugin with no ResourceHandle data attached. The name of the kubelet plugin invoked will match the DriverName set in the ResourceClaimStatus this AllocationResult is embedded in.")
    shareable: Optional[StrictBool] = Field(None, description="Shareable determines whether the resource supports more than one consumer at a time.")
    __properties = ["availableOnNodes", "resourceHandles", "shareable"]

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

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

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

        _obj = V1alpha2AllocationResult.parse_obj({
            "available_on_nodes": V1NodeSelector.from_dict(obj.get("availableOnNodes")) if obj.get("availableOnNodes") is not None else None,
            "resource_handles": [V1alpha2ResourceHandle.from_dict(_item) for _item in obj.get("resourceHandles")] if obj.get("resourceHandles") is not None else None,
            "shareable": obj.get("shareable")
        })
        return _obj


