# 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.asn_details import AsnDetails
from test_results_api.models.path_vis_endpoint import PathVisEndpoint
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 PathVisTestResult(BaseModel):
    """
    PathVisTestResult
    """ # 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 target server.", alias="serverIp")
    system_metrics: Optional[SystemMetrics] = Field(default=None, alias="systemMetrics")
    vpn_profile: Optional[VpnProfile] = Field(default=None, alias="vpnProfile")
    asn_details: Optional[AsnDetails] = Field(default=None, alias="asnDetails")
    server: Optional[StrictStr] = Field(default=None, description="Target server, including port.")
    source_ip: Optional[StrictStr] = Field(default=None, description="IP address of source endpoint agent.", alias="sourceIp")
    source_prefix: Optional[StrictStr] = Field(default=None, description="IP prefix of source endpoint agent.", alias="sourcePrefix")
    location: Optional[StrictStr] = Field(default=None, description="Geographic location of the pathvis.")
    endpoints: Optional[List[PathVisEndpoint]] = Field(default=None, description="Shows an iteration of path trace, with each iteration specified by a pathId.")
    __properties: ClassVar[List[str]] = ["agentId", "aid", "roundId", "serverIp", "systemMetrics", "vpnProfile", "asnDetails", "server", "sourceIp", "sourcePrefix", "location", "endpoints"]

    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 PathVisTestResult 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
                "agent_id",
                "round_id",
                "server_ip",
                "server",
                "source_ip",
                "source_prefix",
                "location",
            },
            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 asn_details
        if self.asn_details:
            _dict['asnDetails'] = self.asn_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in endpoints (list)
        _items = []
        if self.endpoints:
            for _item in self.endpoints:
                if _item:
                    _items.append(_item.to_dict())
            _dict['endpoints'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Dict) -> Self:
        """Create an instance of PathVisTestResult 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,
            "asnDetails": AsnDetails.from_dict(obj.get("asnDetails")) if obj.get("asnDetails") is not None else None,
            "server": obj.get("server"),
            "sourceIp": obj.get("sourceIp"),
            "sourcePrefix": obj.get("sourcePrefix"),
            "location": obj.get("location"),
            "endpoints": [PathVisEndpoint.from_dict(_item) for _item in obj.get("endpoints")] if obj.get("endpoints") is not None else None
        })
        return _obj


