# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from instana_client.models.call_relation import CallRelation
from typing import Optional, Set
from typing_extensions import Self

class GetTraceDownloadResultItem(BaseModel):
    """
    Represents an array of call group item containing several attributes that describe its properties. The item includes fields such as cursor, metrics, name, and timestamp, which provide detailed information about the item. 
    """ # noqa: E501
    call_count: Optional[StrictInt] = Field(default=None, description="Number of calls in a trace.", alias="callCount")
    cursor: Optional[Dict[str, Any]] = Field(default=None, description="Cursor to use between successive queries")
    destination: Optional[CallRelation] = None
    duration: Optional[StrictInt] = Field(default=None, description="The total time taken for the entire operation of a call, from the moment the request was initiated to when the response was received. The time measured is in milliseconds. This is also known as latency of a call.")
    error_count: Optional[StrictInt] = Field(default=None, description="Represents whether the call is erroneous or not. 0 is not erroneous and 1 is erroneous.", alias="errorCount")
    foreign_parent_id: Optional[StrictStr] = Field(default=None, alias="foreignParentId")
    id: Optional[StrictStr] = Field(default=None, description="The call ID. A unique identifier for an individual call. For example: `1bcad5c82338deaf`.")
    min_self_time: Optional[StrictInt] = Field(default=None, description="The smallest self time in the batch. May be null to indicate that `minSelfTime` is unknown when this node has only an exit span and no children. The time measured is in milliseconds.", alias="minSelfTime")
    name: Optional[StrictStr] = Field(default=None, description="Name of the call. For example: `GET /articles/:id`.")
    network_time: Optional[StrictInt] = Field(default=None, description="exit span duration - entry span duration", alias="networkTime")
    parent_id: Optional[StrictStr] = Field(default=None, description="The parent call id, referring to another call in the same trace which triggered the processing associated with this call.", alias="parentId")
    timestamp: Optional[StrictInt] = Field(default=None, description="The timestamp when the call or request was initiated. For example, Unix epoch time in milliseconds `1735532879870` is `Monday, 30 December 2024 04:27:59.870 GMT`")
    __properties: ClassVar[List[str]] = ["callCount", "cursor", "destination", "duration", "errorCount", "foreignParentId", "id", "minSelfTime", "name", "networkTime", "parentId", "timestamp"]

    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 GetTraceDownloadResultItem 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 destination
        if self.destination:
            _dict['destination'] = self.destination.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "callCount": obj.get("callCount"),
            "cursor": obj.get("cursor"),
            "destination": CallRelation.from_dict(obj["destination"]) if obj.get("destination") is not None else None,
            "duration": obj.get("duration"),
            "errorCount": obj.get("errorCount"),
            "foreignParentId": obj.get("foreignParentId"),
            "id": obj.get("id"),
            "minSelfTime": obj.get("minSelfTime"),
            "name": obj.get("name"),
            "networkTime": obj.get("networkTime"),
            "parentId": obj.get("parentId"),
            "timestamp": obj.get("timestamp")
        })
        return _obj


