# coding: utf-8

"""
    

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from goodmem._generated.models.ping_endpoint_info import PingEndpointInfo
from goodmem._generated.models.ping_timing import PingTiming
from typing import Optional, Set
from typing_extensions import Self

class PingResult(BaseModel):
    """
    Result from an individual ping probe
    """ # noqa: E501
    endpoint: PingEndpointInfo
    seq: StrictInt = Field(description="Sequential probe number (1-based)")
    bytes_sent: StrictInt = Field(description="Payload bytes transmitted", alias="bytesSent")
    bytes_received: StrictInt = Field(description="Payload bytes received", alias="bytesReceived")
    ok: StrictBool = Field(description="True when the provider responded successfully within the timeout")
    http_status: StrictInt = Field(description="Provider HTTP status code or equivalent transport status", alias="httpStatus")
    error_message: Optional[StrictStr] = Field(default=None, description="Human-readable error message when ok=false", alias="errorMessage")
    rtt_ms: Union[StrictFloat, StrictInt] = Field(description="Observed round-trip latency in milliseconds", alias="rttMs")
    timing: PingTiming
    metadata: Optional[Dict[str, StrictStr]] = Field(default=None, description="Additional provider metadata (request IDs, throttling signals, etc.)")
    __properties: ClassVar[List[str]] = ["endpoint", "seq", "bytesSent", "bytesReceived", "ok", "httpStatus", "errorMessage", "rttMs", "timing", "metadata"]

    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 PingResult 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 endpoint
        if self.endpoint:
            _dict['endpoint'] = self.endpoint.to_dict()
        # override the default output from pydantic by calling `to_dict()` of timing
        if self.timing:
            _dict['timing'] = self.timing.to_dict()
        # set to None if error_message (nullable) is None
        # and model_fields_set contains the field
        if self.error_message is None and "error_message" in self.model_fields_set:
            _dict['errorMessage'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "endpoint": PingEndpointInfo.from_dict(obj["endpoint"]) if obj.get("endpoint") is not None else None,
            "seq": obj.get("seq"),
            "bytesSent": obj.get("bytesSent"),
            "bytesReceived": obj.get("bytesReceived"),
            "ok": obj.get("ok"),
            "httpStatus": obj.get("httpStatus"),
            "errorMessage": obj.get("errorMessage"),
            "rttMs": obj.get("rttMs"),
            "timing": PingTiming.from_dict(obj["timing"]) if obj.get("timing") is not None else None,
            "metadata": obj.get("metadata")
        })
        return _obj


