# coding: utf-8

"""
    Ivy Analytics API

    API for data ingestion

    The version of the OpenAPI document: 0.1.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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from ivyanalytics.models.assigned_to import AssignedTo
from ivyanalytics.models.author import Author
from ivyanalytics.models.body import Body
from ivyanalytics.models.external_id import ExternalId
from typing import Optional, Set
from typing_extensions import Self

class Conversation(BaseModel):
    """
    Conversation
    """ # noqa: E501
    type: StrictStr
    id: StrictStr
    part_type: StrictStr
    body: Optional[Body] = None
    created_at: StrictInt
    updated_at: StrictInt
    notified_at: StrictInt
    assigned_to: Optional[AssignedTo] = None
    author: Author
    attachments: List[Any]
    external_id: Optional[ExternalId] = None
    redacted: StrictBool
    __properties: ClassVar[List[str]] = ["type", "id", "part_type", "body", "created_at", "updated_at", "notified_at", "assigned_to", "author", "attachments", "external_id", "redacted"]

    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 Conversation 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 body
        if self.body:
            _dict['body'] = self.body.to_dict()
        # override the default output from pydantic by calling `to_dict()` of assigned_to
        if self.assigned_to:
            _dict['assigned_to'] = self.assigned_to.to_dict()
        # override the default output from pydantic by calling `to_dict()` of author
        if self.author:
            _dict['author'] = self.author.to_dict()
        # override the default output from pydantic by calling `to_dict()` of external_id
        if self.external_id:
            _dict['external_id'] = self.external_id.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "type": obj.get("type"),
            "id": obj.get("id"),
            "part_type": obj.get("part_type"),
            "body": Body.from_dict(obj["body"]) if obj.get("body") is not None else None,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "notified_at": obj.get("notified_at"),
            "assigned_to": AssignedTo.from_dict(obj["assigned_to"]) if obj.get("assigned_to") is not None else None,
            "author": Author.from_dict(obj["author"]) if obj.get("author") is not None else None,
            "attachments": obj.get("attachments"),
            "external_id": ExternalId.from_dict(obj["external_id"]) if obj.get("external_id") is not None else None,
            "redacted": obj.get("redacted")
        })
        return _obj


