# coding: utf-8

"""
    Mentortools Deep Agent API

    FastAPI service for running Mentortools deep agent

    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 typing import Dict, List, Optional
from pydantic import BaseModel, Field, StrictBool, StrictStr, conlist, constr
from deep_agent_sdk.models.chat_message_attachment import ChatMessageAttachment
from deep_agent_sdk.models.dynamic_skill_input import DynamicSkillInput
from deep_agent_sdk.models.portal_info import PortalInfo
from deep_agent_sdk.models.run_assistant_context import RunAssistantContext
from deep_agent_sdk.models.run_chat_context import RunChatContext
from deep_agent_sdk.models.run_user_context import RunUserContext

class RunCreateRequest(BaseModel):
    """
    Request schema for creating a new run.  # noqa: E501
    """
    user: RunUserContext = Field(default=..., description="User context")
    assistant: RunAssistantContext = Field(default=..., description="Assistant context")
    chat: RunChatContext = Field(default=..., description="Chat context")
    message: StrictStr = Field(default=..., description="User message to send to the agent")
    request_id: Optional[StrictStr] = Field(default=None, description="Optional request ID for tracing")
    attachments: Optional[conlist(ChatMessageAttachment, max_items=10)] = Field(default=None, description="Optional attachments to include with the message")
    tool_availability_overrides: Optional[Dict[str, StrictBool]] = Field(default=None, description="Tool availability overrides. Keys are tool names, True enables a default-off tool, False disables a default-on tool.")
    skill_availability_overrides: Optional[Dict[str, StrictBool]] = Field(default=None, description="Skill availability overrides. Keys are skill names, True enables a default-off skill, False disables a default-on skill.")
    dynamic_skills: Optional[conlist(DynamicSkillInput, max_items=20)] = Field(default=None, description="Skills passed as inline content, available to orchestrator and all subagents.")
    portal_info: Optional[PortalInfo] = Field(default=None, description="Portal context — language, domain, owner info")
    name_chat: Optional[StrictBool] = Field(default=False, description="When true, auto-generate a chat name from the initial prompt")
    identity_name: Optional[constr(strict=True, max_length=200)] = Field(default=None, description="Display name shown in the system prompt heading. Defaults to 'MentorAgent' when null.")
    identity_tone: Optional[constr(strict=True, max_length=200)] = Field(default=None, description="Short tone descriptor (e.g. 'playful', 'concise and warm').")
    identity_personality: Optional[constr(strict=True, max_length=1000)] = Field(default=None, description="Free-text personality / role description shown after the identity line.")
    user_info: Optional[constr(strict=True, max_length=4000)] = Field(default=None, description="Plain-text info about the human user the agent is helping (e.g. role, background, preferences).")
    academy: Optional[constr(strict=True, max_length=4000)] = Field(default=None, description="Plain-text info about the academy / portal (e.g. niche, audience, brand voice).")
    goal: Optional[constr(strict=True, max_length=4000)] = Field(default=None, description="Plain-text long-term goal of the user + academy engagement.")
    __properties = ["user", "assistant", "chat", "message", "request_id", "attachments", "tool_availability_overrides", "skill_availability_overrides", "dynamic_skills", "portal_info", "name_chat", "identity_name", "identity_tone", "identity_personality", "user_info", "academy", "goal"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> RunCreateRequest:
        """Create an instance of RunCreateRequest from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of user
        if self.user:
            _dict['user'] = self.user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of assistant
        if self.assistant:
            _dict['assistant'] = self.assistant.to_dict()
        # override the default output from pydantic by calling `to_dict()` of chat
        if self.chat:
            _dict['chat'] = self.chat.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in attachments (list)
        _items = []
        if self.attachments:
            for _item in self.attachments:
                if _item:
                    _items.append(_item.to_dict())
            _dict['attachments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in dynamic_skills (list)
        _items = []
        if self.dynamic_skills:
            for _item in self.dynamic_skills:
                if _item:
                    _items.append(_item.to_dict())
            _dict['dynamic_skills'] = _items
        # override the default output from pydantic by calling `to_dict()` of portal_info
        if self.portal_info:
            _dict['portal_info'] = self.portal_info.to_dict()
        # set to None if request_id (nullable) is None
        # and __fields_set__ contains the field
        if self.request_id is None and "request_id" in self.__fields_set__:
            _dict['request_id'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> RunCreateRequest:
        """Create an instance of RunCreateRequest from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return RunCreateRequest.parse_obj(obj)

        _obj = RunCreateRequest.parse_obj({
            "user": RunUserContext.from_dict(obj.get("user")) if obj.get("user") is not None else None,
            "assistant": RunAssistantContext.from_dict(obj.get("assistant")) if obj.get("assistant") is not None else None,
            "chat": RunChatContext.from_dict(obj.get("chat")) if obj.get("chat") is not None else None,
            "message": obj.get("message"),
            "request_id": obj.get("request_id"),
            "attachments": [ChatMessageAttachment.from_dict(_item) for _item in obj.get("attachments")] if obj.get("attachments") is not None else None,
            "tool_availability_overrides": obj.get("tool_availability_overrides"),
            "skill_availability_overrides": obj.get("skill_availability_overrides"),
            "dynamic_skills": [DynamicSkillInput.from_dict(_item) for _item in obj.get("dynamic_skills")] if obj.get("dynamic_skills") is not None else None,
            "portal_info": PortalInfo.from_dict(obj.get("portal_info")) if obj.get("portal_info") is not None else None,
            "name_chat": obj.get("name_chat") if obj.get("name_chat") is not None else False,
            "identity_name": obj.get("identity_name"),
            "identity_tone": obj.get("identity_tone"),
            "identity_personality": obj.get("identity_personality"),
            "user_info": obj.get("user_info"),
            "academy": obj.get("academy"),
            "goal": obj.get("goal")
        })
        return _obj


