# coding: utf-8

"""
    XingChen 开放接口定义

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

    The version of the OpenAPI document: v2
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Optional

from pydantic import BaseModel, Field, StrictBool, StrictStr, conlist

from xingchen.models.advanced_settings import AdvancedSettings
from xingchen.models.character_key import CharacterKey
from xingchen.models.chat_context import ChatContext
from xingchen.models.function_call import Function, FunctionChoice, Plugin
from xingchen.models.memory import Memory
from xingchen.models.message import Message
from xingchen.models.model_parameters import ModelParameters
from xingchen.models.scenario import Scenario
from xingchen.models.user_profile import UserProfile


class ChatReqParams(BaseModel):
    """
    ChatReqParams
    """
    bot_profile: CharacterKey = Field(..., alias="botProfile")
    messages: conlist(Message, max_items=50, min_items=1) = Field(...)
    sample_messages: conlist(Message) = Field(None, alias="sampleMessages")
    advanced_settings: Optional[AdvancedSettings] = Field(None, alias="advancedSettings")
    model_parameters: Optional[ModelParameters] = Field(None, alias="modelParameters")
    user_profile: Optional[UserProfile] = Field(None, alias="userProfile")
    scenario: Optional[Scenario] = None
    streaming: Optional[StrictBool] = None
    source: Optional[StrictStr] = None
    functions: conlist(Function, max_items=50) = Field(None, alias="functionList")
    function_choice: Optional[FunctionChoice] = Field(None, alias="functionChoice")
    plugins: conlist(Plugin, max_items=50) = Field(None, alias="pluginList")
    context: Optional[ChatContext] = Field(None, alias="context")
    memory: Optional[Memory] = Field(None, alias="memory")

    __properties = ["botProfile", "messages", "sampleMessages", "advancedSettings",
                    "modelParameters", "userProfile", "scenario", "streaming", "context", "source", "functionList",
                    "functionChoice", "pluginList", "context", "memory"]

    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) -> ChatReqParams:
        """Create an instance of ChatReqParams 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 bot_profile
        if self.bot_profile:
            _dict['botProfile'] = self.bot_profile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in messages (list)
        _items = []
        if self.messages:
            for _item in self.messages:
                if _item:
                    _items.append(_item.to_dict())
            _dict['messages'] = _items
        # override the default output from pydantic by calling `to_dict()` of advanced_settings
        if self.advanced_settings:
            _dict['advancedSettings'] = self.advanced_settings.to_dict()
        # override the default output from pydantic by calling `to_dict()` of model_parameters
        if self.model_parameters:
            _dict['modelParameters'] = self.model_parameters.to_dict()
        # override the default output from pydantic by calling `to_dict()` of user_profile
        if self.user_profile:
            _dict['userProfile'] = self.user_profile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of scenario
        if self.scenario:
            _dict['scenario'] = self.scenario.to_dict()
        if self.context:
            _dict['context'] = self.context.to_dict()

        _items = []
        if self.functions:
            for _item in self.functions:
                if _item:
                    _items.append(_item)
            _dict['functionList'] = _items

        _items = []
        if self.plugins:
            for _item in self.plugins:
                if _item:
                    _items.append(_item)
            _dict['pluginList'] = _items

        if self.function_choice:
            _dict['functionChoice'] = self.function_choice.to_dict()

        return _dict

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

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

        _obj = ChatReqParams.parse_obj({
            "bot_profile": CharacterKey.from_dict(obj.get("botProfile")) if obj.get("botProfile") is not None else None,
            "messages": [Message.from_dict(_item) for _item in obj.get("messages")] if obj.get(
                "messages") is not None else None,
            "advanced_settings": AdvancedSettings.from_dict(obj.get("advancedSettings")) if obj.get(
                "advancedSettings") is not None else None,
            "model_parameters": ModelParameters.from_dict(obj.get("modelParameters")) if obj.get(
                "modelParameters") is not None else None,
            "user_profile": UserProfile.from_dict(obj.get("userProfile")) if obj.get(
                "userProfile") is not None else None,
            "scenario": Scenario.from_dict(obj.get("scenario")) if obj.get("scenario") is not None else None,
            "streaming": obj.get("streaming"),
            "source": obj.get("source"),
            "functions": [Function.from_dict(_item) for _item in obj.get("functionList")] if obj.get("functionList") is not None else None,
            "plugins": [Plugin.from_dict(_item) for _item in obj.get("pluginList")] if obj.get("pluginList") is not None else None,
            "function_choice": FunctionChoice.from_dict(obj.get("functionChoice")) if obj.get("functionChoice") is not None else None,
            "context": ChatContext.from_dict(obj.get("context")) if obj.get("context") is not None else None,
            "memory": Memory.from_dict(obj.get("memory")) if obj.get("memory") is not None else None
        })
        return _obj
