# coding: utf-8

"""
    Artifact Keeper API

    Enterprise artifact registry supporting 45+ package formats.

    The version of the OpenAPI document: 1.0.0-rc.3
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class PeerResponse(BaseModel):
    """
    PeerResponse
    """ # noqa: E501
    bandwidth_estimate_bps: Optional[StrictInt] = None
    bytes_transferred_total: StrictInt
    id: StrictStr
    last_probed_at: Optional[datetime] = None
    last_transfer_at: Optional[datetime] = None
    latency_ms: Optional[StrictInt] = None
    shared_artifacts_count: StrictInt
    shared_chunks_count: StrictInt
    status: StrictStr
    target_peer_id: StrictStr
    transfer_failure_count: StrictInt
    transfer_success_count: StrictInt
    __properties: ClassVar[List[str]] = ["bandwidth_estimate_bps", "bytes_transferred_total", "id", "last_probed_at", "last_transfer_at", "latency_ms", "shared_artifacts_count", "shared_chunks_count", "status", "target_peer_id", "transfer_failure_count", "transfer_success_count"]

    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 PeerResponse 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,
        )
        # set to None if bandwidth_estimate_bps (nullable) is None
        # and model_fields_set contains the field
        if self.bandwidth_estimate_bps is None and "bandwidth_estimate_bps" in self.model_fields_set:
            _dict['bandwidth_estimate_bps'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "bandwidth_estimate_bps": obj.get("bandwidth_estimate_bps"),
            "bytes_transferred_total": obj.get("bytes_transferred_total"),
            "id": obj.get("id"),
            "last_probed_at": obj.get("last_probed_at"),
            "last_transfer_at": obj.get("last_transfer_at"),
            "latency_ms": obj.get("latency_ms"),
            "shared_artifacts_count": obj.get("shared_artifacts_count"),
            "shared_chunks_count": obj.get("shared_chunks_count"),
            "status": obj.get("status"),
            "target_peer_id": obj.get("target_peer_id"),
            "transfer_failure_count": obj.get("transfer_failure_count"),
            "transfer_success_count": obj.get("transfer_success_count")
        })
        return _obj


