# coding: utf-8

"""
Hatchet API

The Hatchet API

The version of the OpenAPI document: 1.0.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from hatchet_sdk.clients.rest.models.otel_span_kind import OtelSpanKind
from hatchet_sdk.clients.rest.models.otel_status_code import OtelStatusCode
from typing import Optional, Set
from typing_extensions import Self


class OtelSpan(BaseModel):
    """
    OtelSpan
    """  # noqa: E501

    trace_id: StrictStr = Field(alias="traceId")
    span_id: StrictStr = Field(alias="spanId")
    parent_span_id: Optional[StrictStr] = Field(default=None, alias="parentSpanId")
    span_name: StrictStr = Field(alias="spanName")
    span_kind: OtelSpanKind = Field(alias="spanKind")
    service_name: StrictStr = Field(alias="serviceName")
    status_code: OtelStatusCode = Field(alias="statusCode")
    status_message: Optional[StrictStr] = Field(default=None, alias="statusMessage")
    duration_ns: StrictInt = Field(alias="durationNs")
    created_at: datetime = Field(alias="createdAt")
    resource_attributes: Optional[Dict[str, StrictStr]] = Field(
        default=None, alias="resourceAttributes"
    )
    span_attributes: Optional[Dict[str, StrictStr]] = Field(
        default=None, alias="spanAttributes"
    )
    scope_name: Optional[StrictStr] = Field(default=None, alias="scopeName")
    scope_version: Optional[StrictStr] = Field(default=None, alias="scopeVersion")
    retry_count: StrictInt = Field(alias="retryCount")
    __properties: ClassVar[List[str]] = [
        "traceId",
        "spanId",
        "parentSpanId",
        "spanName",
        "spanKind",
        "serviceName",
        "statusCode",
        "statusMessage",
        "durationNs",
        "createdAt",
        "resourceAttributes",
        "spanAttributes",
        "scopeName",
        "scopeVersion",
        "retryCount",
    ]

    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 OtelSpan 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: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of OtelSpan from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate(
            {
                "traceId": obj.get("traceId"),
                "spanId": obj.get("spanId"),
                "parentSpanId": obj.get("parentSpanId"),
                "spanName": obj.get("spanName"),
                "spanKind": obj.get("spanKind"),
                "serviceName": obj.get("serviceName"),
                "statusCode": obj.get("statusCode"),
                "statusMessage": obj.get("statusMessage"),
                "durationNs": obj.get("durationNs"),
                "createdAt": obj.get("createdAt"),
                "resourceAttributes": obj.get("resourceAttributes"),
                "spanAttributes": obj.get("spanAttributes"),
                "scopeName": obj.get("scopeName"),
                "scopeVersion": obj.get("scopeVersion"),
                "retryCount": obj.get("retryCount"),
            }
        )
        return _obj
