# 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, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from intervals_icu_client.models.activity import Activity
from typing import Optional, Set
from typing_extensions import Self

class Message(BaseModel):
    """
    Message
    """ # noqa: E501
    id: Optional[StrictInt] = None
    athlete_id: Optional[StrictStr] = None
    name: Optional[StrictStr] = None
    created: Optional[datetime] = None
    type: Optional[StrictStr] = None
    content: Optional[StrictStr] = None
    activity_id: Optional[StrictStr] = None
    start_index: Optional[StrictInt] = None
    end_index: Optional[StrictInt] = None
    answer: Optional[StrictStr] = None
    activity: Optional[Activity] = None
    attachment_url: Optional[StrictStr] = None
    attachment_mime_type: Optional[StrictStr] = None
    deleted: Optional[datetime] = None
    deleted_by_id: Optional[StrictStr] = None
    join_group_id: Optional[StrictInt] = None
    accept_coaching_group_id: Optional[StrictInt] = None
    seen: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["id", "athlete_id", "name", "created", "type", "content", "activity_id", "start_index", "end_index", "answer", "activity", "attachment_url", "attachment_mime_type", "deleted", "deleted_by_id", "join_group_id", "accept_coaching_group_id", "seen"]

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

        if value not in set(['TEXT', 'FOLLOW_REQ', 'COACH_REQ', 'COACH_ME_REQ', 'ACTIVITY', 'NOTE', 'JOIN_REQ', 'ACCEPT_COACHING_GROUP']):
            raise ValueError("must be one of enum values ('TEXT', 'FOLLOW_REQ', 'COACH_REQ', 'COACH_ME_REQ', 'ACTIVITY', 'NOTE', 'JOIN_REQ', 'ACCEPT_COACHING_GROUP')")
        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 Message 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 activity
        if self.activity:
            _dict['activity'] = self.activity.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Message 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"),
            "athlete_id": obj.get("athlete_id"),
            "name": obj.get("name"),
            "created": obj.get("created"),
            "type": obj.get("type"),
            "content": obj.get("content"),
            "activity_id": obj.get("activity_id"),
            "start_index": obj.get("start_index"),
            "end_index": obj.get("end_index"),
            "answer": obj.get("answer"),
            "activity": Activity.from_dict(obj["activity"]) if obj.get("activity") is not None else None,
            "attachment_url": obj.get("attachment_url"),
            "attachment_mime_type": obj.get("attachment_mime_type"),
            "deleted": obj.get("deleted"),
            "deleted_by_id": obj.get("deleted_by_id"),
            "join_group_id": obj.get("join_group_id"),
            "accept_coaching_group_id": obj.get("accept_coaching_group_id"),
            "seen": obj.get("seen")
        })
        return _obj


