# coding: utf-8

"""
    Mentortools Access Server

    Mentortools service for Access Packages with lazy access resolution

    The version of the OpenAPI document: 0.1.0
    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, StrictInt, StrictStr, conlist
from access_server_connector.models.lock_reason import LockReason
from access_server_connector.models.resource_type import ResourceType
from access_server_connector.models.state import State
from access_server_connector.models.winning_layer import WinningLayer

class NodeAccessOut(BaseModel):
    """
    NodeAccessOut
    """
    resource_type: ResourceType = Field(...)
    resource_id: StrictInt = Field(...)
    state: State = Field(...)
    allowed: StrictBool = Field(...)
    available_at: Optional[StrictInt] = Field(...)
    expires_at: Optional[StrictInt] = Field(...)
    lock_reason: Optional[LockReason] = Field(...)
    winning_layer: Optional[WinningLayer] = Field(...)
    reasons: conlist(StrictInt) = Field(...)
    expired_message: Optional[StrictStr] = None
    children: Optional[conlist(NodeAccessOut)] = None
    __properties = ["resource_type", "resource_id", "state", "allowed", "available_at", "expires_at", "lock_reason", "winning_layer", "reasons", "expired_message", "children"]

    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) -> NodeAccessOut:
        """Create an instance of NodeAccessOut 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 children (list)
        _items = []
        if self.children:
            for _item in self.children:
                if _item:
                    _items.append(_item.to_dict())
            _dict['children'] = _items
        # set to None if available_at (nullable) is None
        # and __fields_set__ contains the field
        if self.available_at is None and "available_at" in self.__fields_set__:
            _dict['available_at'] = None

        # set to None if expires_at (nullable) is None
        # and __fields_set__ contains the field
        if self.expires_at is None and "expires_at" in self.__fields_set__:
            _dict['expires_at'] = None

        # set to None if lock_reason (nullable) is None
        # and __fields_set__ contains the field
        if self.lock_reason is None and "lock_reason" in self.__fields_set__:
            _dict['lock_reason'] = None

        # set to None if winning_layer (nullable) is None
        # and __fields_set__ contains the field
        if self.winning_layer is None and "winning_layer" in self.__fields_set__:
            _dict['winning_layer'] = None

        # set to None if expired_message (nullable) is None
        # and __fields_set__ contains the field
        if self.expired_message is None and "expired_message" in self.__fields_set__:
            _dict['expired_message'] = None

        return _dict

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

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

        _obj = NodeAccessOut.parse_obj({
            "resource_type": obj.get("resource_type"),
            "resource_id": obj.get("resource_id"),
            "state": obj.get("state"),
            "allowed": obj.get("allowed"),
            "available_at": obj.get("available_at"),
            "expires_at": obj.get("expires_at"),
            "lock_reason": obj.get("lock_reason"),
            "winning_layer": obj.get("winning_layer"),
            "reasons": obj.get("reasons"),
            "expired_message": obj.get("expired_message"),
            "children": [NodeAccessOut.from_dict(_item) for _item in obj.get("children")] if obj.get("children") is not None else None
        })
        return _obj

NodeAccessOut.update_forward_refs()

