# coding: utf-8

"""
    Endpoint Test Results API

    Retrieve results for scheduled and dynamic tests on endpoint agents.

    The version of the OpenAPI document: 7.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 typing import Any, ClassVar, Dict, List, Optional, Union
from pydantic import BaseModel, StrictBool, StrictFloat, StrictInt, StrictStr
from pydantic import Field
from test_results_api.models.network_profile import NetworkProfile
from test_results_api.models.real_user_test_network_gateway_ping import RealUserTestNetworkGatewayPing
from test_results_api.models.real_user_test_network_ping import RealUserTestNetworkPing
from test_results_api.models.real_user_test_network_traceroute import RealUserTestNetworkTraceroute
from test_results_api.models.real_user_test_network_vpn_ping import RealUserTestNetworkVpnPing
from test_results_api.models.real_user_test_network_vpn_traceroute import RealUserTestNetworkVpnTraceroute
from test_results_api.models.system_metrics import SystemMetrics
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class RealUserTestNetwork(BaseModel):
    """
    Contains details about network profile and conditions during session.
    """ # noqa: E501
    network_profile: Optional[NetworkProfile] = Field(default=None, alias="networkProfile")
    system_metrics: Optional[SystemMetrics] = Field(default=None, alias="systemMetrics")
    gateway_ping: Optional[RealUserTestNetworkGatewayPing] = Field(default=None, alias="gatewayPing")
    ping: Optional[RealUserTestNetworkPing] = None
    traceroute: Optional[RealUserTestNetworkTraceroute] = None
    connect_rtt: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Represents the number of milliseconds required to establish TCP connectivity with the target.", alias="connectRtt")
    is_icmp_blocked: Optional[StrictBool] = Field(default=None, description="Set to `true` if network target is blocking ICMP echo (ping) queries.", alias="isIcmpBlocked")
    errors: Optional[List[StrictStr]] = Field(default=None, description="Array of string representing possible network errors.")
    vpn_ping: Optional[RealUserTestNetworkVpnPing] = Field(default=None, alias="vpnPing")
    vpn_traceroute: Optional[RealUserTestNetworkVpnTraceroute] = Field(default=None, alias="vpnTraceroute")
    __properties: ClassVar[List[str]] = ["networkProfile", "systemMetrics", "gatewayPing", "ping", "traceroute", "connectRtt", "isIcmpBlocked", "errors", "vpnPing", "vpnTraceroute"]

    model_config = {
        "populate_by_name": True,
        "validate_assignment": True
    }


    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) -> Self:
        """Create an instance of RealUserTestNetwork 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
                "connect_rtt",
                "is_icmp_blocked",
                "errors",
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of network_profile
        if self.network_profile:
            _dict['networkProfile'] = self.network_profile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of system_metrics
        if self.system_metrics:
            _dict['systemMetrics'] = self.system_metrics.to_dict()
        # override the default output from pydantic by calling `to_dict()` of gateway_ping
        if self.gateway_ping:
            _dict['gatewayPing'] = self.gateway_ping.to_dict()
        # override the default output from pydantic by calling `to_dict()` of ping
        if self.ping:
            _dict['ping'] = self.ping.to_dict()
        # override the default output from pydantic by calling `to_dict()` of traceroute
        if self.traceroute:
            _dict['traceroute'] = self.traceroute.to_dict()
        # override the default output from pydantic by calling `to_dict()` of vpn_ping
        if self.vpn_ping:
            _dict['vpnPing'] = self.vpn_ping.to_dict()
        # override the default output from pydantic by calling `to_dict()` of vpn_traceroute
        if self.vpn_traceroute:
            _dict['vpnTraceroute'] = self.vpn_traceroute.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of RealUserTestNetwork from a dict"""
        if obj is None:
            return None

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

        _obj = cls.model_validate({
            "networkProfile": NetworkProfile.from_dict(obj.get("networkProfile")) if obj.get("networkProfile") is not None else None,
            "systemMetrics": SystemMetrics.from_dict(obj.get("systemMetrics")) if obj.get("systemMetrics") is not None else None,
            "gatewayPing": RealUserTestNetworkGatewayPing.from_dict(obj.get("gatewayPing")) if obj.get("gatewayPing") is not None else None,
            "ping": RealUserTestNetworkPing.from_dict(obj.get("ping")) if obj.get("ping") is not None else None,
            "traceroute": RealUserTestNetworkTraceroute.from_dict(obj.get("traceroute")) if obj.get("traceroute") is not None else None,
            "connectRtt": obj.get("connectRtt"),
            "isIcmpBlocked": obj.get("isIcmpBlocked"),
            "errors": obj.get("errors"),
            "vpnPing": RealUserTestNetworkVpnPing.from_dict(obj.get("vpnPing")) if obj.get("vpnPing") is not None else None,
            "vpnTraceroute": RealUserTestNetworkVpnTraceroute.from_dict(obj.get("vpnTraceroute")) if obj.get("vpnTraceroute") is not None else None
        })
        return _obj


