# 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 .v1_non_resource_rule import V1NonResourceRule
from .v1_resource_rule import V1ResourceRule

class V1SubjectRulesReviewStatus(BaseModel):
    """
    SubjectRulesReviewStatus contains the result of a rules check. This check can be incomplete depending on the set of authorizers the server is configured with and any errors experienced during evaluation. Because authorization rules are additive, if a rule appears in a list it's safe to assume the subject has that permission, even if that list is incomplete.  # noqa: E501
    """
    evaluation_error: Optional[StrictStr] = Field(None, alias="evaluationError", description="EvaluationError can appear in combination with Rules. It indicates an error occurred during rule evaluation, such as an authorizer that doesn't support rule evaluation, and that ResourceRules and/or NonResourceRules may be incomplete.")
    incomplete: StrictBool = Field(..., description="Incomplete is true when the rules returned by this call are incomplete. This is most commonly encountered when an authorizer, such as an external authorizer, doesn't support rules evaluation.")
    non_resource_rules: conlist(V1NonResourceRule) = Field(..., alias="nonResourceRules", description="NonResourceRules is the list of actions the subject is allowed to perform on non-resources. The list ordering isn't significant, may contain duplicates, and possibly be incomplete.")
    resource_rules: conlist(V1ResourceRule) = Field(..., alias="resourceRules", description="ResourceRules is the list of actions the subject is allowed to perform on resources. The list ordering isn't significant, may contain duplicates, and possibly be incomplete.")
    __properties = ["evaluationError", "incomplete", "nonResourceRules", "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) -> V1SubjectRulesReviewStatus:
        """Create an instance of V1SubjectRulesReviewStatus 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 non_resource_rules (list)
        _items = []
        if self.non_resource_rules:
            for _item in self.non_resource_rules:
                if _item:
                    _items.append(_item.to_dict())
            _dict['nonResourceRules'] = _items
        # 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) -> V1SubjectRulesReviewStatus:
        """Create an instance of V1SubjectRulesReviewStatus from a dict"""
        if obj is None:
            return None

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

        _obj = V1SubjectRulesReviewStatus.parse_obj({
            "evaluation_error": obj.get("evaluationError"),
            "incomplete": obj.get("incomplete"),
            "non_resource_rules": [V1NonResourceRule.from_dict(_item) for _item in obj.get("nonResourceRules")] if obj.get("nonResourceRules") is not None else None,
            "resource_rules": [V1ResourceRule.from_dict(_item) for _item in obj.get("resourceRules")] if obj.get("resourceRules") is not None else None
        })
        return _obj


