# coding: utf-8

"""
    Instana REST API documentation

    Documentation for INSTANA REST API

    The version of the OpenAPI document: 1.309.1268
    Contact: support@instana.com
    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from instana_client.models.tag_tree_node import TagTreeNode
from typing import Optional, Set
from typing_extensions import Self

class TagTreeLevel(BaseModel):
    """
    The name of the tag dataset (tagTree) which can contain one or more tags as its attributes or children. Eg: `Call`. Consider this as the root of the tree where it has tags as attributes or children. 
    """ # noqa: E501
    children: List[TagTreeNode] = Field(description="Children tags of tagTree")
    description: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=512)]] = Field(default=None, description="The description provided, if any.")
    icon: Optional[Annotated[str, Field(min_length=0, strict=True, max_length=128)]] = Field(default=None, description="Each tag has an Icon which can be seen on the drop down list in Unbounded Analytics. If there is an icon, there will be a string associated with it. Eg: For for all `TAG` under `Call` tagTreeNode, the `icon` value is `lib_application_call`. ")
    label: Annotated[str, Field(min_length=0, strict=True, max_length=128)] = Field(description="The name of the tagTreeNode. Eg: `Commonly Used`, `Application`.")
    queryable: Optional[StrictBool] = None
    score_boost: Optional[StrictInt] = Field(default=None, description="By default it is `null` if it is not set explictily by IBM Instana. The purpose of this parameter is to rank the tagTree. For eg: some set of tags are frequently used. Tags under `Commonly used` is frequently used, so it will come up on top of the drop down list of `Query Builder` in `Unbounded Analytics`. Higher the scoreBoost, higher the ranking. ", alias="scoreBoost")
    type: Optional[StrictStr] = Field(default=None, description="Type would be either `LEVEL` or `TAG` depending on whether the tag has any child tags or not respectively.")
    __properties: ClassVar[List[str]] = ["children", "description", "icon", "label", "queryable", "scoreBoost", "type"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of TagTreeLevel from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            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_children in self.children:
                if _item_children:
                    _items.append(_item_children.to_dict())
            _dict['children'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of TagTreeLevel from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "children": [TagTreeNode.from_dict(_item) for _item in obj["children"]] if obj.get("children") is not None else None,
            "description": obj.get("description"),
            "icon": obj.get("icon"),
            "label": obj.get("label"),
            "queryable": obj.get("queryable"),
            "scoreBoost": obj.get("scoreBoost"),
            "type": obj.get("type")
        })
        return _obj


