# 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 .v1_label_selector import V1LabelSelector

class V1PodAffinityTerm(BaseModel):
    """
    Defines a set of pods (namely those matching the labelSelector relative to the given namespace(s)) that this pod should be co-located (affinity) or not co-located (anti-affinity) with, where co-located is defined as running on a node whose value of the label with key <topologyKey> matches that of any node on which a pod of the set of pods is running  # noqa: E501
    """
    label_selector: Optional[V1LabelSelector] = Field(None, alias="labelSelector")
    match_label_keys: Optional[conlist(StrictStr)] = Field(None, alias="matchLabelKeys", description="MatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `LabelSelector` as `key in (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both MatchLabelKeys and LabelSelector. Also, MatchLabelKeys cannot be set when LabelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.")
    mismatch_label_keys: Optional[conlist(StrictStr)] = Field(None, alias="mismatchLabelKeys", description="MismatchLabelKeys is a set of pod label keys to select which pods will be taken into consideration. The keys are used to lookup values from the incoming pod labels, those key-value labels are merged with `LabelSelector` as `key notin (value)` to select the group of existing pods which pods will be taken into consideration for the incoming pod's pod (anti) affinity. Keys that don't exist in the incoming pod labels will be ignored. The default value is empty. The same key is forbidden to exist in both MismatchLabelKeys and LabelSelector. Also, MismatchLabelKeys cannot be set when LabelSelector isn't set. This is an alpha field and requires enabling MatchLabelKeysInPodAffinity feature gate.")
    namespace_selector: Optional[V1LabelSelector] = Field(None, alias="namespaceSelector")
    namespaces: Optional[conlist(StrictStr)] = Field(None, description="namespaces specifies a static list of namespace names that the term applies to. The term is applied to the union of the namespaces listed in this field and the ones selected by namespaceSelector. null or empty namespaces list and null namespaceSelector means \"this pod's namespace\".")
    topology_key: StrictStr = Field(..., alias="topologyKey", description="This pod should be co-located (affinity) or not co-located (anti-affinity) with the pods matching the labelSelector in the specified namespaces, where co-located is defined as running on a node whose value of the label with key topologyKey matches that of any node on which any of the selected pods is running. Empty topologyKey is not allowed.")
    __properties = ["labelSelector", "matchLabelKeys", "mismatchLabelKeys", "namespaceSelector", "namespaces", "topologyKey"]

    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) -> V1PodAffinityTerm:
        """Create an instance of V1PodAffinityTerm 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 label_selector
        if self.label_selector:
            _dict['labelSelector'] = self.label_selector.to_dict()
        # override the default output from pydantic by calling `to_dict()` of namespace_selector
        if self.namespace_selector:
            _dict['namespaceSelector'] = self.namespace_selector.to_dict()
        return _dict

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

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

        _obj = V1PodAffinityTerm.parse_obj({
            "label_selector": V1LabelSelector.from_dict(obj.get("labelSelector")) if obj.get("labelSelector") is not None else None,
            "match_label_keys": obj.get("matchLabelKeys"),
            "mismatch_label_keys": obj.get("mismatchLabelKeys"),
            "namespace_selector": V1LabelSelector.from_dict(obj.get("namespaceSelector")) if obj.get("namespaceSelector") is not None else None,
            "namespaces": obj.get("namespaces"),
            "topology_key": obj.get("topologyKey")
        })
        return _obj


