# 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
from pydantic import BaseModel, StrictInt, StrictStr
from pydantic import Field
from test_results_api.models.account_group_id import AccountGroupId
from test_results_api.models.http_error_type import HttpErrorType
from test_results_api.models.http_test_result_headers import HttpTestResultHeaders
from test_results_api.models.network_profile import NetworkProfile
from test_results_api.models.system_metrics import SystemMetrics
from test_results_api.models.vpn_profile import VpnProfile
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class HttpTestResult(BaseModel):
    """
    HttpTestResult
    """ # noqa: E501
    agent_id: Optional[StrictStr] = Field(default=None, description="Unique ID of endpoint agent, from `/endpoint/agents` endpoint.", alias="agentId")
    aid: Optional[AccountGroupId] = None
    round_id: Optional[StrictInt] = Field(default=None, description="Epoch time (seconds) indicating the start time of the round.", alias="roundId")
    server_ip: Optional[StrictStr] = Field(default=None, description="IP address of destination server.", alias="serverIp")
    system_metrics: Optional[SystemMetrics] = Field(default=None, alias="systemMetrics")
    vpn_profile: Optional[VpnProfile] = Field(default=None, alias="vpnProfile")
    network_profile: Optional[NetworkProfile] = Field(default=None, alias="networkProfile")
    connect_time: Optional[StrictInt] = Field(default=None, description="Time required to establish a TCP connection to the server in milliseconds.", alias="connectTime")
    dns_time: Optional[StrictInt] = Field(default=None, description="Time required to resolve DNS in milliseconds.", alias="dnsTime")
    error_type: Optional[HttpErrorType] = Field(default=None, alias="errorType")
    error_details: Optional[StrictStr] = Field(default=None, description="Error details, if an error were encountered.", alias="errorDetails")
    headers: Optional[HttpTestResultHeaders] = None
    num_redirects: Optional[StrictInt] = Field(default=None, description="Number of redirects.", alias="numRedirects")
    receive_time: Optional[StrictInt] = Field(default=None, description="Elapsed time between first and last byte of response in milliseconds.", alias="receiveTime")
    redirect_time: Optional[StrictInt] = Field(default=None, description="Cumulative redirect timing in milliseconds.", alias="redirectTime")
    response_code: Optional[StrictInt] = Field(default=None, description="HTTP response code.", alias="responseCode")
    response_time: Optional[StrictInt] = Field(default=None, description="Time to first byte in milliseconds.", alias="responseTime")
    ssl_time: Optional[StrictInt] = Field(default=None, description="Time to negotiate SSL/TLS in milliseconds.", alias="sslTime")
    total_time: Optional[StrictInt] = Field(default=None, description="Total time is the response time + receive time.", alias="totalTime")
    wait_time: Optional[StrictInt] = Field(default=None, description="Time elapsed between completion of request and first byte of response in milliseconds.", alias="waitTime")
    wire_size: Optional[StrictInt] = Field(default=None, description="Size of content in bytes.", alias="wireSize")
    __properties: ClassVar[List[str]] = ["agentId", "aid", "roundId", "serverIp", "systemMetrics", "vpnProfile", "networkProfile", "connectTime", "dnsTime", "errorType", "errorDetails", "headers", "numRedirects", "receiveTime", "redirectTime", "responseCode", "responseTime", "sslTime", "totalTime", "waitTime", "wireSize"]

    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 HttpTestResult 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
                "agent_id",
                "round_id",
                "server_ip",
                "connect_time",
                "dns_time",
                "error_details",
                "num_redirects",
                "receive_time",
                "redirect_time",
                "response_code",
                "response_time",
                "ssl_time",
                "total_time",
                "wait_time",
                "wire_size",
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of aid
        if self.aid:
            _dict['aid'] = self.aid.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 vpn_profile
        if self.vpn_profile:
            _dict['vpnProfile'] = self.vpn_profile.to_dict()
        # 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 headers
        if self.headers:
            _dict['headers'] = self.headers.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "agentId": obj.get("agentId"),
            "aid": AccountGroupId.from_dict(obj.get("aid")) if obj.get("aid") is not None else None,
            "roundId": obj.get("roundId"),
            "serverIp": obj.get("serverIp"),
            "systemMetrics": SystemMetrics.from_dict(obj.get("systemMetrics")) if obj.get("systemMetrics") is not None else None,
            "vpnProfile": VpnProfile.from_dict(obj.get("vpnProfile")) if obj.get("vpnProfile") is not None else None,
            "networkProfile": NetworkProfile.from_dict(obj.get("networkProfile")) if obj.get("networkProfile") is not None else None,
            "connectTime": obj.get("connectTime"),
            "dnsTime": obj.get("dnsTime"),
            "errorType": obj.get("errorType"),
            "errorDetails": obj.get("errorDetails"),
            "headers": HttpTestResultHeaders.from_dict(obj.get("headers")) if obj.get("headers") is not None else None,
            "numRedirects": obj.get("numRedirects"),
            "receiveTime": obj.get("receiveTime"),
            "redirectTime": obj.get("redirectTime"),
            "responseCode": obj.get("responseCode"),
            "responseTime": obj.get("responseTime"),
            "sslTime": obj.get("sslTime"),
            "totalTime": obj.get("totalTime"),
            "waitTime": obj.get("waitTime"),
            "wireSize": obj.get("wireSize")
        })
        return _obj


