# coding: utf-8

"""
    allure-testops-service

    Branch **HEAD**  Commit **623f6ed302ba4b651cf9040faca4635af2d93b7c**

    The version of the OpenAPI document: 25.4.1
    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 importlib import import_module
from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from src.client.generated.models.node_type import NodeType
from typing import Optional, Set
from typing_extensions import Self

from typing import TYPE_CHECKING
if TYPE_CHECKING:
    from src.client.generated.models.test_case_light_tree_node_dto import TestCaseLightTreeNodeDto
    from src.client.generated.models.test_case_tree_leaf_dto_v2 import TestCaseTreeLeafDtoV2

class TestCaseTreeNodeDto(BaseModel):
    """
    TestCaseTreeNodeDto
    """ # noqa: E501
    id: Optional[StrictInt] = None
    name: Optional[StrictStr] = None
    type: Optional[NodeType] = None
    __properties: ClassVar[List[str]] = ["id", "name", "type"]

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


    # JSON field name that stores the object type
    __discriminator_property_name: ClassVar[str] = 'type'

    # discriminator mappings
    __discriminator_value_class_map: ClassVar[Dict[str, str]] = {
        'TestCaseLightTreeNodeDto': 'TestCaseLightTreeNodeDto','TestCaseTreeLeafDtoV2': 'TestCaseTreeLeafDtoV2'
    }

    @classmethod
    def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
        """Returns the discriminator value (object type) of the data"""
        discriminator_value = obj[cls.__discriminator_property_name]
        if discriminator_value:
            return cls.__discriminator_value_class_map.get(discriminator_value)
        else:
            return None

    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[Union[TestCaseLightTreeNodeDto, TestCaseTreeLeafDtoV2]]:
        """Create an instance of TestCaseTreeNodeDto 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,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[TestCaseLightTreeNodeDto, TestCaseTreeLeafDtoV2]]:
        """Create an instance of TestCaseTreeNodeDto from a dict"""
        # look up the object type based on discriminator mapping
        object_type = cls.get_discriminator_value(obj)
        if object_type ==  'TestCaseLightTreeNodeDto':
            return import_module("src.client.generated.models.test_case_light_tree_node_dto").TestCaseLightTreeNodeDto.from_dict(obj)
        if object_type ==  'TestCaseTreeLeafDtoV2':
            return import_module("src.client.generated.models.test_case_tree_leaf_dto_v2").TestCaseTreeLeafDtoV2.from_dict(obj)

        raise ValueError("TestCaseTreeNodeDto failed to lookup discriminator value from " +
                            json.dumps(obj) + ". Discriminator property name: " + cls.__discriminator_property_name +
                            ", mapping: " + json.dumps(cls.__discriminator_value_class_map))


