# coding: utf-8

"""
    Ephor.ai

    Collaborative AI

    The version of the OpenAPI document: 1.3.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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from ephor_server_ti_client.models.artifact import Artifact
from ephor_server_ti_client.models.attachment import Attachment
from ephor_server_ti_client.models.expert_comment import ExpertComment
from ephor_server_ti_client.models.message_expert_summary import MessageExpertSummary
from ephor_server_ti_client.models.source import Source
from typing import Optional, Set
from typing_extensions import Self

class ChannelMessage(BaseModel):
    """
    Message
    """ # noqa: E501
    id: Optional[StrictStr] = None
    channel_id: Optional[StrictStr] = None
    user_id: Optional[StrictStr] = None
    user_name: Optional[StrictStr] = None
    artifacts: Optional[List[Artifact]] = None
    sources: Optional[List[Source]] = None
    slm_leaderboard: Optional[StrictStr] = None
    context_analysis: Optional[StrictStr] = None
    cost_analysis: Optional[StrictStr] = None
    lm_type: Optional[StrictStr] = None
    user_picture: Optional[StrictStr] = None
    content: Optional[StrictStr] = None
    timestamp: Optional[datetime] = None
    attachments: Optional[List[Attachment]] = None
    parent_id: Optional[StrictStr] = None
    feedback_id: Optional[StrictStr] = None
    feedback_type: Optional[StrictStr] = None
    feedback_category: Optional[StrictStr] = None
    expert_summary: Optional[MessageExpertSummary] = None
    pinned_expert_comments: Optional[List[ExpertComment]] = None
    expert_comments: Optional[List[ExpertComment]] = None
    __properties: ClassVar[List[str]] = ["id", "channel_id", "user_id", "user_name", "artifacts", "sources", "slm_leaderboard", "context_analysis", "cost_analysis", "lm_type", "user_picture", "content", "timestamp", "attachments", "parent_id", "feedback_id", "feedback_type", "feedback_category", "expert_summary", "pinned_expert_comments", "expert_comments"]

    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 ChannelMessage 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 each item in artifacts (list)
        _items = []
        if self.artifacts:
            for _item_artifacts in self.artifacts:
                if _item_artifacts:
                    _items.append(_item_artifacts.to_dict())
            _dict['artifacts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in sources (list)
        _items = []
        if self.sources:
            for _item_sources in self.sources:
                if _item_sources:
                    _items.append(_item_sources.to_dict())
            _dict['sources'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in attachments (list)
        _items = []
        if self.attachments:
            for _item_attachments in self.attachments:
                if _item_attachments:
                    _items.append(_item_attachments.to_dict())
            _dict['attachments'] = _items
        # override the default output from pydantic by calling `to_dict()` of expert_summary
        if self.expert_summary:
            _dict['expert_summary'] = self.expert_summary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in pinned_expert_comments (list)
        _items = []
        if self.pinned_expert_comments:
            for _item_pinned_expert_comments in self.pinned_expert_comments:
                if _item_pinned_expert_comments:
                    _items.append(_item_pinned_expert_comments.to_dict())
            _dict['pinned_expert_comments'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in expert_comments (list)
        _items = []
        if self.expert_comments:
            for _item_expert_comments in self.expert_comments:
                if _item_expert_comments:
                    _items.append(_item_expert_comments.to_dict())
            _dict['expert_comments'] = _items
        # set to None if id (nullable) is None
        # and model_fields_set contains the field
        if self.id is None and "id" in self.model_fields_set:
            _dict['id'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "channel_id": obj.get("channel_id"),
            "user_id": obj.get("user_id"),
            "user_name": obj.get("user_name"),
            "artifacts": [Artifact.from_dict(_item) for _item in obj["artifacts"]] if obj.get("artifacts") is not None else None,
            "sources": [Source.from_dict(_item) for _item in obj["sources"]] if obj.get("sources") is not None else None,
            "slm_leaderboard": obj.get("slm_leaderboard"),
            "context_analysis": obj.get("context_analysis"),
            "cost_analysis": obj.get("cost_analysis"),
            "lm_type": obj.get("lm_type"),
            "user_picture": obj.get("user_picture"),
            "content": obj.get("content"),
            "timestamp": obj.get("timestamp"),
            "attachments": [Attachment.from_dict(_item) for _item in obj["attachments"]] if obj.get("attachments") is not None else None,
            "parent_id": obj.get("parent_id"),
            "feedback_id": obj.get("feedback_id"),
            "feedback_type": obj.get("feedback_type"),
            "feedback_category": obj.get("feedback_category"),
            "expert_summary": MessageExpertSummary.from_dict(obj["expert_summary"]) if obj.get("expert_summary") is not None else None,
            "pinned_expert_comments": [ExpertComment.from_dict(_item) for _item in obj["pinned_expert_comments"]] if obj.get("pinned_expert_comments") is not None else None,
            "expert_comments": [ExpertComment.from_dict(_item) for _item in obj["expert_comments"]] if obj.get("expert_comments") is not None else None
        })
        return _obj


