# coding: utf-8

"""
    Arthur Scope

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from arthur_client.api_bindings.models.creation_source import CreationSource
from arthur_client.api_bindings.models.infrastructure import Infrastructure
from arthur_client.api_bindings.models.sub_agent_response import SubAgentResponse
from arthur_client.api_bindings.models.tool_response import ToolResponse
from typing import Optional, Set
from typing_extensions import Self

class UnregisteredAgentResponse(BaseModel):
    """
    Response model for an unregistered agent with assigned ID.
    """ # noqa: E501
    created_at: datetime = Field(description="Time of record creation.")
    updated_at: datetime = Field(description="Time of last record update.")
    id: StrictStr = Field(description="ID of the unregistered agent.")
    name: StrictStr = Field(description="Name of the unregistered agent.")
    creation_source: CreationSource = Field(description="Information about how this agent was created.")
    first_detected: datetime = Field(description="Timestamp when this agent was first detected.")
    num_spans: Optional[StrictInt] = None
    infrastructure: Infrastructure = Field(description="Infrastructure where this agent is running.")
    data_plane_id: StrictStr = Field(description="UUID of the data plane where this agent was detected.")
    tools: Optional[List[ToolResponse]] = Field(default=None, description="List of tools used by this agent.")
    sub_agents: Optional[List[SubAgentResponse]] = Field(default=None, description="List of sub-agents used by this agent.")
    model_id: Optional[StrictStr] = None
    model_name: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["created_at", "updated_at", "id", "name", "creation_source", "first_detected", "num_spans", "infrastructure", "data_plane_id", "tools", "sub_agents", "model_id", "model_name"]

    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 UnregisteredAgentResponse 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,
        )
        # override the default output from pydantic by calling `to_dict()` of creation_source
        if self.creation_source:
            _dict['creation_source'] = self.creation_source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in tools (list)
        _items = []
        if self.tools:
            for _item_tools in self.tools:
                if _item_tools:
                    _items.append(_item_tools.to_dict())
            _dict['tools'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in sub_agents (list)
        _items = []
        if self.sub_agents:
            for _item_sub_agents in self.sub_agents:
                if _item_sub_agents:
                    _items.append(_item_sub_agents.to_dict())
            _dict['sub_agents'] = _items
        # set to None if num_spans (nullable) is None
        # and model_fields_set contains the field
        if self.num_spans is None and "num_spans" in self.model_fields_set:
            _dict['num_spans'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "id": obj.get("id"),
            "name": obj.get("name"),
            "creation_source": CreationSource.from_dict(obj["creation_source"]) if obj.get("creation_source") is not None else None,
            "first_detected": obj.get("first_detected"),
            "num_spans": obj.get("num_spans"),
            "infrastructure": obj.get("infrastructure"),
            "data_plane_id": obj.get("data_plane_id"),
            "tools": [ToolResponse.from_dict(_item) for _item in obj["tools"]] if obj.get("tools") is not None else None,
            "sub_agents": [SubAgentResponse.from_dict(_item) for _item in obj["sub_agents"]] if obj.get("sub_agents") is not None else None,
            "model_id": obj.get("model_id"),
            "model_name": obj.get("model_name")
        })
        return _obj


