# coding: utf-8

"""
    Slack Web API

    One way to interact with the Slack platform is its HTTP RPC-based Web API, a collection of methods requiring OAuth 2.0-based user, bot, or workspace tokens blessed with related OAuth scopes.

    The version of the OpenAPI document: 1.7.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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from slack_beta_ti.models.objs_bot_profile import ObjsBotProfile
from slack_beta_ti.models.objs_comment import ObjsComment
from slack_beta_ti.models.objs_file import ObjsFile
from slack_beta_ti.models.objs_reaction import ObjsReaction
from slack_beta_ti.models.objs_user_profile_short import ObjsUserProfileShort
from typing import Optional, Set
from typing_extensions import Self

class ObjsMessage(BaseModel):
    """
    ObjsMessage
    """ # noqa: E501
    attachments: Optional[Annotated[List[Dict[str, Any]], Field(min_length=1)]] = None
    blocks: Optional[List[Dict[str, Any]]] = Field(default=None, description="This is a very loose definition, in the future, we'll populate this with deeper schema in this definition namespace.")
    bot_id: Optional[Dict[str, Any]] = None
    bot_profile: Optional[ObjsBotProfile] = None
    client_msg_id: Optional[StrictStr] = None
    comment: Optional[ObjsComment] = None
    display_as_bot: Optional[StrictBool] = None
    file: Optional[ObjsFile] = None
    files: Optional[Annotated[List[ObjsFile], Field(min_length=1)]] = None
    icons: Optional[Dict[str, Any]] = None
    inviter: Optional[Annotated[str, Field(strict=True)]] = None
    is_delayed_message: Optional[StrictBool] = None
    is_intro: Optional[StrictBool] = None
    is_starred: Optional[StrictBool] = None
    last_read: Optional[Annotated[str, Field(strict=True)]] = None
    latest_reply: Optional[Annotated[str, Field(strict=True)]] = None
    name: Optional[StrictStr] = None
    old_name: Optional[StrictStr] = None
    parent_user_id: Optional[Annotated[str, Field(strict=True)]] = None
    permalink: Optional[StrictStr] = None
    pinned_to: Optional[List[Annotated[str, Field(strict=True)]]] = None
    purpose: Optional[StrictStr] = None
    reactions: Optional[List[ObjsReaction]] = None
    reply_count: Optional[StrictInt] = None
    reply_users: Optional[Annotated[List[Annotated[str, Field(strict=True)]], Field(min_length=1)]] = None
    reply_users_count: Optional[StrictInt] = None
    source_team: Optional[Annotated[str, Field(strict=True)]] = None
    subscribed: Optional[StrictBool] = None
    subtype: Optional[StrictStr] = None
    team: Optional[Annotated[str, Field(strict=True)]] = None
    text: StrictStr
    thread_ts: Optional[Annotated[str, Field(strict=True)]] = None
    topic: Optional[StrictStr] = None
    ts: Annotated[str, Field(strict=True)]
    type: StrictStr
    unread_count: Optional[StrictInt] = None
    upload: Optional[StrictBool] = None
    user: Optional[Annotated[str, Field(strict=True)]] = None
    user_profile: Optional[ObjsUserProfileShort] = None
    user_team: Optional[Annotated[str, Field(strict=True)]] = None
    username: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["attachments", "blocks", "bot_id", "bot_profile", "client_msg_id", "comment", "display_as_bot", "file", "files", "icons", "inviter", "is_delayed_message", "is_intro", "is_starred", "last_read", "latest_reply", "name", "old_name", "parent_user_id", "permalink", "pinned_to", "purpose", "reactions", "reply_count", "reply_users", "reply_users_count", "source_team", "subscribed", "subtype", "team", "text", "thread_ts", "topic", "ts", "type", "unread_count", "upload", "user", "user_profile", "user_team", "username"]

    @field_validator('inviter')
    def inviter_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[UW][A-Z0-9]{2,}$", value):
            raise ValueError(r"must validate the regular expression /^[UW][A-Z0-9]{2,}$/")
        return value

    @field_validator('last_read')
    def last_read_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d{10}\.\d{6}$", value):
            raise ValueError(r"must validate the regular expression /^\d{10}\.\d{6}$/")
        return value

    @field_validator('latest_reply')
    def latest_reply_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d{10}\.\d{6}$", value):
            raise ValueError(r"must validate the regular expression /^\d{10}\.\d{6}$/")
        return value

    @field_validator('parent_user_id')
    def parent_user_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[UW][A-Z0-9]{2,}$", value):
            raise ValueError(r"must validate the regular expression /^[UW][A-Z0-9]{2,}$/")
        return value

    @field_validator('source_team')
    def source_team_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[TE][A-Z0-9]{8,}$", value):
            raise ValueError(r"must validate the regular expression /^[TE][A-Z0-9]{8,}$/")
        return value

    @field_validator('team')
    def team_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[TE][A-Z0-9]{8,}$", value):
            raise ValueError(r"must validate the regular expression /^[TE][A-Z0-9]{8,}$/")
        return value

    @field_validator('thread_ts')
    def thread_ts_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^\d{10}\.\d{6}$", value):
            raise ValueError(r"must validate the regular expression /^\d{10}\.\d{6}$/")
        return value

    @field_validator('ts')
    def ts_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^\d{10}\.\d{6}$", value):
            raise ValueError(r"must validate the regular expression /^\d{10}\.\d{6}$/")
        return value

    @field_validator('user')
    def user_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[UW][A-Z0-9]{2,}$", value):
            raise ValueError(r"must validate the regular expression /^[UW][A-Z0-9]{2,}$/")
        return value

    @field_validator('user_team')
    def user_team_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[TE][A-Z0-9]{8,}$", value):
            raise ValueError(r"must validate the regular expression /^[TE][A-Z0-9]{8,}$/")
        return value

    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 ObjsMessage 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 bot_profile
        if self.bot_profile:
            _dict['bot_profile'] = self.bot_profile.to_dict()
        # override the default output from pydantic by calling `to_dict()` of comment
        if self.comment:
            _dict['comment'] = self.comment.to_dict()
        # override the default output from pydantic by calling `to_dict()` of file
        if self.file:
            _dict['file'] = self.file.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in files (list)
        _items = []
        if self.files:
            for _item_files in self.files:
                if _item_files:
                    _items.append(_item_files.to_dict())
            _dict['files'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in reactions (list)
        _items = []
        if self.reactions:
            for _item_reactions in self.reactions:
                if _item_reactions:
                    _items.append(_item_reactions.to_dict())
            _dict['reactions'] = _items
        # override the default output from pydantic by calling `to_dict()` of user_profile
        if self.user_profile:
            _dict['user_profile'] = self.user_profile.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "attachments": obj.get("attachments"),
            "blocks": obj.get("blocks"),
            "bot_id": obj.get("bot_id"),
            "bot_profile": ObjsBotProfile.from_dict(obj["bot_profile"]) if obj.get("bot_profile") is not None else None,
            "client_msg_id": obj.get("client_msg_id"),
            "comment": ObjsComment.from_dict(obj["comment"]) if obj.get("comment") is not None else None,
            "display_as_bot": obj.get("display_as_bot"),
            "file": ObjsFile.from_dict(obj["file"]) if obj.get("file") is not None else None,
            "files": [ObjsFile.from_dict(_item) for _item in obj["files"]] if obj.get("files") is not None else None,
            "icons": obj.get("icons"),
            "inviter": obj.get("inviter"),
            "is_delayed_message": obj.get("is_delayed_message"),
            "is_intro": obj.get("is_intro"),
            "is_starred": obj.get("is_starred"),
            "last_read": obj.get("last_read"),
            "latest_reply": obj.get("latest_reply"),
            "name": obj.get("name"),
            "old_name": obj.get("old_name"),
            "parent_user_id": obj.get("parent_user_id"),
            "permalink": obj.get("permalink"),
            "pinned_to": obj.get("pinned_to"),
            "purpose": obj.get("purpose"),
            "reactions": [ObjsReaction.from_dict(_item) for _item in obj["reactions"]] if obj.get("reactions") is not None else None,
            "reply_count": obj.get("reply_count"),
            "reply_users": obj.get("reply_users"),
            "reply_users_count": obj.get("reply_users_count"),
            "source_team": obj.get("source_team"),
            "subscribed": obj.get("subscribed"),
            "subtype": obj.get("subtype"),
            "team": obj.get("team"),
            "text": obj.get("text"),
            "thread_ts": obj.get("thread_ts"),
            "topic": obj.get("topic"),
            "ts": obj.get("ts"),
            "type": obj.get("type"),
            "unread_count": obj.get("unread_count"),
            "upload": obj.get("upload"),
            "user": obj.get("user"),
            "user_profile": ObjsUserProfileShort.from_dict(obj["user_profile"]) if obj.get("user_profile") is not None else None,
            "user_team": obj.get("user_team"),
            "username": obj.get("username")
        })
        return _obj


