# 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
from .v1alpha1_named_rule_with_operations import V1alpha1NamedRuleWithOperations

class V1alpha1MatchResources(BaseModel):
    """
    MatchResources decides whether to run the admission control policy on an object based on whether it meets the match criteria. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)  # noqa: E501
    """
    exclude_resource_rules: Optional[conlist(V1alpha1NamedRuleWithOperations)] = Field(None, alias="excludeResourceRules", description="ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about. The exclude rules take precedence over include rules (if a resource matches both, it is excluded)")
    match_policy: Optional[StrictStr] = Field(None, alias="matchPolicy", description="matchPolicy defines how the \"MatchResources\" list is used to match incoming requests. Allowed values are \"Exact\" or \"Equivalent\".  - Exact: match a request only if it exactly matches a specified rule. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, but \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would not be sent to the ValidatingAdmissionPolicy.  - Equivalent: match a request if modifies a resource listed in rules, even via another API group or version. For example, if deployments can be modified via apps/v1, apps/v1beta1, and extensions/v1beta1, and \"rules\" only included `apiGroups:[\"apps\"], apiVersions:[\"v1\"], resources: [\"deployments\"]`, a request to apps/v1beta1 or extensions/v1beta1 would be converted to apps/v1 and sent to the ValidatingAdmissionPolicy.  Defaults to \"Equivalent\"")
    namespace_selector: Optional[V1LabelSelector] = Field(None, alias="namespaceSelector")
    object_selector: Optional[V1LabelSelector] = Field(None, alias="objectSelector")
    resource_rules: Optional[conlist(V1alpha1NamedRuleWithOperations)] = Field(None, alias="resourceRules", description="ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches. The policy cares about an operation if it matches _any_ Rule.")
    __properties = ["excludeResourceRules", "matchPolicy", "namespaceSelector", "objectSelector", "resourceRules"]

    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) -> V1alpha1MatchResources:
        """Create an instance of V1alpha1MatchResources 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 each item in exclude_resource_rules (list)
        _items = []
        if self.exclude_resource_rules:
            for _item in self.exclude_resource_rules:
                if _item:
                    _items.append(_item.to_dict())
            _dict['excludeResourceRules'] = _items
        # override the default output from pydantic by calling `to_dict()` of namespace_selector
        if self.namespace_selector:
            _dict['namespaceSelector'] = self.namespace_selector.to_dict()
        # override the default output from pydantic by calling `to_dict()` of object_selector
        if self.object_selector:
            _dict['objectSelector'] = self.object_selector.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in resource_rules (list)
        _items = []
        if self.resource_rules:
            for _item in self.resource_rules:
                if _item:
                    _items.append(_item.to_dict())
            _dict['resourceRules'] = _items
        return _dict

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

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

        _obj = V1alpha1MatchResources.parse_obj({
            "exclude_resource_rules": [V1alpha1NamedRuleWithOperations.from_dict(_item) for _item in obj.get("excludeResourceRules")] if obj.get("excludeResourceRules") is not None else None,
            "match_policy": obj.get("matchPolicy"),
            "namespace_selector": V1LabelSelector.from_dict(obj.get("namespaceSelector")) if obj.get("namespaceSelector") is not None else None,
            "object_selector": V1LabelSelector.from_dict(obj.get("objectSelector")) if obj.get("objectSelector") is not None else None,
            "resource_rules": [V1alpha1NamedRuleWithOperations.from_dict(_item) for _item in obj.get("resourceRules")] if obj.get("resourceRules") is not None else None
        })
        return _obj


