# coding: utf-8

"""
    Administrative API

    Manage users, accounts, and account groups in the ThousandEyes platform using the Administrative API. This API provides the following operations to manage your organization:     * `/account-groups`: Account groups are used to divide an organization into different sections. These operations can be used to create, retrieve, update and delete account groups.   * `/users`: Create, retrieve, update and delete users within an organization.    * `/roles`: Create, retrieve and update roles for the current user.    * `/permissions`: Retrieve all assignable permissions. Used in the context of modifying roles.    * `/audit-user-events`: Retrieve all activity log events.    For more information about the administrative models, see [Account Management](https://docs.thousandeyes.com/product-documentation/user-management).

    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, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from thousandeyes_sdk.administrative.models.account_group import AccountGroup
from thousandeyes_sdk.administrative.models.cluster_member import ClusterMember
from thousandeyes_sdk.administrative.models.enterprise_agent_ipv6_policy import EnterpriseAgentIpv6Policy
from thousandeyes_sdk.administrative.models.enterprise_agent_state import EnterpriseAgentState
from thousandeyes_sdk.administrative.models.error_detail import ErrorDetail
from thousandeyes_sdk.administrative.models.interface_ip_mapping import InterfaceIpMapping
from thousandeyes_sdk.administrative.models.simple_test import SimpleTest
from typing import Optional, Set
from typing_extensions import Self

class EnterpriseAgentData(BaseModel):
    """
    EnterpriseAgentData
    """ # noqa: E501
    test_ids: Optional[List[StrictInt]] = Field(default=None, description="List of test IDs assigned to the agent.", alias="testIds")
    tests: Optional[List[SimpleTest]] = Field(default=None, description="List of tests. See `/tests` for more information.")
    cluster_members: Optional[List[ClusterMember]] = Field(default=None, description="If an enterprise agent is clustered, detailed information about each cluster member will be shown as array entries in the clusterMembers field. This field is not shown for Enterprise Agents in standalone mode, or for Cloud Agents.", alias="clusterMembers")
    utilization: Optional[StrictInt] = Field(default=None, description="Shows overall utilization percentage (online Enterprise Agents and Enterprise Clusters only).")
    account_groups: Optional[List[AccountGroup]] = Field(default=None, description="List of account groups. See /accounts-groups to pull a list of account IDs", alias="accountGroups")
    ipv6_policy: Optional[EnterpriseAgentIpv6Policy] = Field(default=None, alias="ipv6Policy")
    error_details: Optional[List[ErrorDetail]] = Field(default=None, description="If an enterprise agent or a cluster member presents at least one error, the errors will be shown as an array of entries in the errorDetails field (Enterprise Agents and Enterprise Cluster members only)", alias="errorDetails")
    hostname: Optional[StrictStr] = Field(default=None, description="Fully qualified domain name of the agent (Enterprise Agents only)")
    last_seen: Optional[datetime] = Field(default=None, description="UTC last seen date (ISO date-time format).", alias="lastSeen")
    agent_state: Optional[EnterpriseAgentState] = Field(default=None, alias="agentState")
    keep_browser_cache: Optional[StrictBool] = Field(default=None, description="Flag indicating if the agent retains cache.", alias="keepBrowserCache")
    created_date: Optional[datetime] = Field(default=None, description="UTC Agent creation date (ISO date-time format).", alias="createdDate")
    target_for_tests: Optional[StrictStr] = Field(default=None, description="Test target IP address.", alias="targetForTests")
    serial_number: Optional[StrictStr] = Field(default=None, description="Serial number of an enterprise agent or cluster member device. This field is not available for Cloud Agents.", alias="serialNumber")
    local_resolution_prefixes: Optional[List[StrictStr]] = Field(default=None, description="To perform rDNS lookups for public IP ranges, this field represents the public IP ranges. The range must be in CIDR notation; for example, 10.1.1.0/24. Maximum of 5 prefixes allowed (Enterprise Agents and Enterprise Agent clusters only).", alias="localResolutionPrefixes")
    interface_ip_mapping: Optional[List[InterfaceIpMapping]] = Field(default=None, alias="interfaceIpMapping")
    __properties: ClassVar[List[str]] = ["testIds", "tests", "clusterMembers", "utilization", "accountGroups", "ipv6Policy", "errorDetails", "hostname", "lastSeen", "agentState", "keepBrowserCache", "createdDate", "targetForTests", "serialNumber", "localResolutionPrefixes", "interfaceIpMapping"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
        extra="allow",
    )


    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 self.model_dump_json(by_alias=True, exclude_unset=True, exclude_none=True)

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of EnterpriseAgentData 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.
        """
        excluded_fields: Set[str] = set([
            "test_ids",
            "cluster_members",
            "utilization",
            "error_details",
            "hostname",
            "last_seen",
            "created_date",
            "serial_number",
            "interface_ip_mapping",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in tests (list)
        _items = []
        if self.tests:
            for _item in self.tests:
                if _item:
                    _items.append(_item.to_dict())
            _dict['tests'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in cluster_members (list)
        _items = []
        if self.cluster_members:
            for _item in self.cluster_members:
                if _item:
                    _items.append(_item.to_dict())
            _dict['clusterMembers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in account_groups (list)
        _items = []
        if self.account_groups:
            for _item in self.account_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['accountGroups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in error_details (list)
        _items = []
        if self.error_details:
            for _item in self.error_details:
                if _item:
                    _items.append(_item.to_dict())
            _dict['errorDetails'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in interface_ip_mapping (list)
        _items = []
        if self.interface_ip_mapping:
            for _item in self.interface_ip_mapping:
                if _item:
                    _items.append(_item.to_dict())
            _dict['interfaceIpMapping'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "testIds": obj.get("testIds"),
            "tests": [SimpleTest.from_dict(_item) for _item in obj["tests"]] if obj.get("tests") is not None else None,
            "clusterMembers": [ClusterMember.from_dict(_item) for _item in obj["clusterMembers"]] if obj.get("clusterMembers") is not None else None,
            "utilization": obj.get("utilization"),
            "accountGroups": [AccountGroup.from_dict(_item) for _item in obj["accountGroups"]] if obj.get("accountGroups") is not None else None,
            "ipv6Policy": obj.get("ipv6Policy"),
            "errorDetails": [ErrorDetail.from_dict(_item) for _item in obj["errorDetails"]] if obj.get("errorDetails") is not None else None,
            "hostname": obj.get("hostname"),
            "lastSeen": obj.get("lastSeen"),
            "agentState": obj.get("agentState"),
            "keepBrowserCache": obj.get("keepBrowserCache"),
            "createdDate": obj.get("createdDate"),
            "targetForTests": obj.get("targetForTests"),
            "serialNumber": obj.get("serialNumber"),
            "localResolutionPrefixes": obj.get("localResolutionPrefixes"),
            "interfaceIpMapping": [InterfaceIpMapping.from_dict(_item) for _item in obj["interfaceIpMapping"]] if obj.get("interfaceIpMapping") is not None else None
        })
        return _obj


