# 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 pprint
import re  # noqa: F401
import json

from datetime import datetime
from typing import Optional, Union
from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from xingchen.models.chat_room_user_dto import ChatRoomUserDTO

class ChatMessageDTO(BaseModel):
    """
    聊天消息  # noqa: E501
    """
    content: Optional[StrictStr] = Field(None, description="消息内容")
    message_type: Optional[StrictStr] = Field(None, alias="messageType", description="消息类型，opening_remarks: 开场白，sys_greetings: 系统问候，user: 用户, character: 角色")
    message_id: Optional[StrictStr] = Field(None, alias="messageId", description="消息ID")
    message_issuer: Optional[ChatRoomUserDTO] = Field(None, alias="messageIssuer")
    session_id: Optional[StrictStr] = Field(None, alias="sessionId", description="消息对话session_id")
    chat_id: Optional[StrictStr] = Field(None, alias="chatId", description="一次对话ID")
    gmt_create: Optional[datetime] = Field(None, alias="gmtCreate", description="消息创建时间")
    is_greeting: Optional[StrictBool] = Field(None, alias="isGreeting", description="是否为开场白")
    rating: Optional[Union[StrictFloat, StrictInt]] = Field(None, description="消息评分")
    regenerate_times: Optional[StrictInt] = Field(None, alias="regenerateTimes", description="重新生成次数")
    __properties = ["content", "messageType", "messageId", "messageIssuer", "sessionId", "chatId", "gmtCreate", "isGreeting", "rating", "regenerateTimes"]

    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) -> ChatMessageDTO:
        """Create an instance of ChatMessageDTO 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 message_issuer
        if self.message_issuer:
            _dict['messageIssuer'] = self.message_issuer.to_dict()
        return _dict

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

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

        _obj = ChatMessageDTO.parse_obj({
            "content": obj.get("content"),
            "message_type": obj.get("messageType"),
            "message_id": obj.get("messageId"),
            "message_issuer": ChatRoomUserDTO.from_dict(obj.get("messageIssuer")) if obj.get("messageIssuer") is not None else None,
            "session_id": obj.get("sessionId"),
            "chat_id": obj.get("chatId"),
            "gmt_create": obj.get("gmtCreate"),
            "is_greeting": obj.get("isGreeting"),
            "rating": obj.get("rating"),
            "regenerate_times": obj.get("regenerateTimes")
        })
        return _obj


