# coding: utf-8

"""
    Equinix Fabric API v4
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from equinix.services.fabricv4.models.cloud_router_command_request_connection import CloudRouterCommandRequestConnection
from typing import Optional, Set
from typing_extensions import Self

class CloudRouterCommandRequestResponse(BaseModel):
    """
    Fabric Cloud Router Command Request
    """ # noqa: E501
    destination: Optional[StrictStr] = Field(default=None, description="Fabric Cloud Router Ping or Traceroute Command Destination")
    source_connection: Optional[CloudRouterCommandRequestConnection] = Field(default=None, alias="sourceConnection")
    timeout: Optional[StrictInt] = Field(default=None, description="Timeout in seconds for Fabric Cloud Router Command:   - For `PING_COMMAND`: Packet timeout duration. The default value is 5.   - For `TRACEROUTE_COMMAND`: Probe timeout duration.     The default value is 2 and it is not configurable. ")
    data_bytes: Optional[Annotated[int, Field(le=9000, strict=True, ge=16)]] = Field(default=64, description="Ping Command DataBytes.  This field is only applicable for commands of type `PING_COMMAND`. ", alias="dataBytes")
    interval: Optional[StrictInt] = Field(default=1000, description="Time in milliseconds between sending each packet. This field is only applicable for commands of type `PING_COMMAND`. ")
    count: Optional[StrictInt] = Field(default=5, description="Total number of ping requests. This field is only applicable for commands of type `PING_COMMAND`. ")
    probes: Optional[StrictInt] = Field(default=3, description="Number of probes for Fabric Cloud Router Traceroute Command. This field is only applicable for commands of type `TRACEROUTE_COMMAND` and is not configurable. ")
    hops_max: Optional[Annotated[int, Field(le=30, strict=True)]] = Field(default=20, description="Maximum number of hops for the traceroute command. This field is only applicable for commands of type `TRACEROUTE_COMMAND`. ", alias="hopsMax")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["destination", "sourceConnection", "timeout", "dataBytes", "interval", "count", "probes", "hopsMax"]

    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 CloudRouterCommandRequestResponse 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of source_connection
        if self.source_connection:
            _dict['sourceConnection'] = self.source_connection.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "destination": obj.get("destination"),
            "sourceConnection": CloudRouterCommandRequestConnection.from_dict(obj["sourceConnection"]) if obj.get("sourceConnection") is not None else None,
            "timeout": obj.get("timeout"),
            "dataBytes": obj.get("dataBytes") if obj.get("dataBytes") is not None else 64,
            "interval": obj.get("interval") if obj.get("interval") is not None else 1000,
            "count": obj.get("count") if obj.get("count") is not None else 5,
            "probes": obj.get("probes") if obj.get("probes") is not None else 3,
            "hopsMax": obj.get("hopsMax") if obj.get("hopsMax") is not None else 20
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


