# 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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from arthur_client.api_bindings.models.agent_creation_source import AgentCreationSource
from arthur_client.api_bindings.models.data_source import DataSource
from arthur_client.api_bindings.models.llm_model import LLMModel
from arthur_client.api_bindings.models.rule_response import RuleResponse
from arthur_client.api_bindings.models.sub_agent import SubAgent
from arthur_client.api_bindings.models.tool import Tool
from typing import Optional, Set
from typing_extensions import Self

class Agent(BaseModel):
    """
    Request model for agent upsert - nested entities without IDs.
    """ # noqa: E501
    name: StrictStr = Field(description="Name of the agent.")
    data_plane_id: StrictStr = Field(description="UUID of the data plane where this agent was detected.")
    task_id: StrictStr = Field(description="UUID of the associated task.")
    creation_source: AgentCreationSource = Field(description="Information about how this agent was created.")
    model_id: Optional[StrictStr] = None
    num_spans: Optional[StrictInt] = Field(default=0, description="Number of spans associated with this agent.")
    is_autocreated: Optional[StrictBool] = Field(default=True, description="Whether this agent was auto-created from traces.")
    rules: Optional[List[RuleResponse]] = Field(default=None, description="Rules associated with this agent's task.")
    last_fetched: Optional[datetime] = None
    muted_until: Optional[datetime] = None
    tools: Optional[List[Tool]] = Field(default=None, description="Tools used by this agent.")
    sub_agents: Optional[List[SubAgent]] = Field(default=None, description="Sub-agents used by this agent.")
    llm_models: Optional[List[LLMModel]] = Field(default=None, description="LLM models used by this agent.")
    data_sources: Optional[List[DataSource]] = Field(default=None, description="Data sources used by this agent.")
    __properties: ClassVar[List[str]] = ["name", "data_plane_id", "task_id", "creation_source", "model_id", "num_spans", "is_autocreated", "rules", "last_fetched", "muted_until", "tools", "sub_agents", "llm_models", "data_sources"]

    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 Agent 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 rules (list)
        _items = []
        if self.rules:
            for _item_rules in self.rules:
                if _item_rules:
                    _items.append(_item_rules.to_dict())
            _dict['rules'] = _items
        # 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
        # override the default output from pydantic by calling `to_dict()` of each item in llm_models (list)
        _items = []
        if self.llm_models:
            for _item_llm_models in self.llm_models:
                if _item_llm_models:
                    _items.append(_item_llm_models.to_dict())
            _dict['llm_models'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in data_sources (list)
        _items = []
        if self.data_sources:
            for _item_data_sources in self.data_sources:
                if _item_data_sources:
                    _items.append(_item_data_sources.to_dict())
            _dict['data_sources'] = _items
        # 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 last_fetched (nullable) is None
        # and model_fields_set contains the field
        if self.last_fetched is None and "last_fetched" in self.model_fields_set:
            _dict['last_fetched'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "data_plane_id": obj.get("data_plane_id"),
            "task_id": obj.get("task_id"),
            "creation_source": AgentCreationSource.from_dict(obj["creation_source"]) if obj.get("creation_source") is not None else None,
            "model_id": obj.get("model_id"),
            "num_spans": obj.get("num_spans") if obj.get("num_spans") is not None else 0,
            "is_autocreated": obj.get("is_autocreated") if obj.get("is_autocreated") is not None else True,
            "rules": [RuleResponse.from_dict(_item) for _item in obj["rules"]] if obj.get("rules") is not None else None,
            "last_fetched": obj.get("last_fetched"),
            "muted_until": obj.get("muted_until"),
            "tools": [Tool.from_dict(_item) for _item in obj["tools"]] if obj.get("tools") is not None else None,
            "sub_agents": [SubAgent.from_dict(_item) for _item in obj["sub_agents"]] if obj.get("sub_agents") is not None else None,
            "llm_models": [LLMModel.from_dict(_item) for _item in obj["llm_models"]] if obj.get("llm_models") is not None else None,
            "data_sources": [DataSource.from_dict(_item) for _item in obj["data_sources"]] if obj.get("data_sources") is not None else None
        })
        return _obj


