# coding: utf-8

"""
    Intervals.icu API

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

    The version of the OpenAPI document: v1.0.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, Field, StrictBool, StrictFloat, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from intervals_icu_client.models.chat_member import ChatMember
from intervals_icu_client.models.folder import Folder
from typing import Optional, Set
from typing_extensions import Self

class Chat(BaseModel):
    """
    Chat
    """ # noqa: E501
    id: Optional[StrictInt] = None
    type: Optional[StrictStr] = None
    coaching_group: Optional[datetime] = None
    updated: Optional[datetime] = None
    name: Optional[StrictStr] = None
    picture: Optional[StrictStr] = None
    description: Optional[StrictStr] = None
    url: Optional[StrictStr] = None
    slug: Optional[StrictStr] = None
    pub: Optional[StrictBool] = None
    join_policy: Optional[StrictStr] = None
    sidebar_logo: Optional[StrictStr] = None
    sidebar_color: Optional[StrictStr] = None
    sidebar_dark: Optional[StrictBool] = None
    sidebar_top_color: Optional[StrictStr] = None
    hide_members: Optional[StrictBool] = None
    members_cannot_chat: Optional[StrictBool] = None
    primary_group: Optional[StrictBool] = None
    coins: Optional[Union[StrictFloat, StrictInt]] = None
    members: Optional[List[ChatMember]] = None
    athlete_id: Optional[StrictStr] = None
    activity_id: Optional[StrictStr] = None
    other_athlete_id: Optional[StrictStr] = None
    other_athlete_sex: Optional[StrictStr] = None
    follows_you: Optional[StrictStr] = None
    you_follow: Optional[StrictStr] = None
    role: Optional[StrictStr] = None
    new_message_count: Optional[StrictInt] = None
    kicked: Optional[datetime] = None
    kicked_by_id: Optional[StrictStr] = None
    last_seen_message_id: Optional[StrictInt] = None
    mute_until: Optional[datetime] = None
    shared_folders: Optional[List[Folder]] = Field(default=None, alias="sharedFolders")
    __properties: ClassVar[List[str]] = ["id", "type", "coaching_group", "updated", "name", "picture", "description", "url", "slug", "pub", "join_policy", "sidebar_logo", "sidebar_color", "sidebar_dark", "sidebar_top_color", "hide_members", "members_cannot_chat", "primary_group", "coins", "members", "athlete_id", "activity_id", "other_athlete_id", "other_athlete_sex", "follows_you", "you_follow", "role", "new_message_count", "kicked", "kicked_by_id", "last_seen_message_id", "mute_until", "sharedFolders"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['PRIVATE', 'GROUP', 'ACTIVITY']):
            raise ValueError("must be one of enum values ('PRIVATE', 'GROUP', 'ACTIVITY')")
        return value

    @field_validator('join_policy')
    def join_policy_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['OPEN', 'ASK', 'INVITE_ONLY']):
            raise ValueError("must be one of enum values ('OPEN', 'ASK', 'INVITE_ONLY')")
        return value

    @field_validator('role')
    def role_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['MEMBER', 'FOLLOWER', 'COACH', 'ADMIN']):
            raise ValueError("must be one of enum values ('MEMBER', 'FOLLOWER', 'COACH', 'ADMIN')")
        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 Chat 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 members (list)
        _items = []
        if self.members:
            for _item_members in self.members:
                if _item_members:
                    _items.append(_item_members.to_dict())
            _dict['members'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in shared_folders (list)
        _items = []
        if self.shared_folders:
            for _item_shared_folders in self.shared_folders:
                if _item_shared_folders:
                    _items.append(_item_shared_folders.to_dict())
            _dict['sharedFolders'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Chat 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"),
            "type": obj.get("type"),
            "coaching_group": obj.get("coaching_group"),
            "updated": obj.get("updated"),
            "name": obj.get("name"),
            "picture": obj.get("picture"),
            "description": obj.get("description"),
            "url": obj.get("url"),
            "slug": obj.get("slug"),
            "pub": obj.get("pub"),
            "join_policy": obj.get("join_policy"),
            "sidebar_logo": obj.get("sidebar_logo"),
            "sidebar_color": obj.get("sidebar_color"),
            "sidebar_dark": obj.get("sidebar_dark"),
            "sidebar_top_color": obj.get("sidebar_top_color"),
            "hide_members": obj.get("hide_members"),
            "members_cannot_chat": obj.get("members_cannot_chat"),
            "primary_group": obj.get("primary_group"),
            "coins": obj.get("coins"),
            "members": [ChatMember.from_dict(_item) for _item in obj["members"]] if obj.get("members") is not None else None,
            "athlete_id": obj.get("athlete_id"),
            "activity_id": obj.get("activity_id"),
            "other_athlete_id": obj.get("other_athlete_id"),
            "other_athlete_sex": obj.get("other_athlete_sex"),
            "follows_you": obj.get("follows_you"),
            "you_follow": obj.get("you_follow"),
            "role": obj.get("role"),
            "new_message_count": obj.get("new_message_count"),
            "kicked": obj.get("kicked"),
            "kicked_by_id": obj.get("kicked_by_id"),
            "last_seen_message_id": obj.get("last_seen_message_id"),
            "mute_until": obj.get("mute_until"),
            "sharedFolders": [Folder.from_dict(_item) for _item in obj["sharedFolders"]] if obj.get("sharedFolders") is not None else None
        })
        return _obj


