# coding: utf-8

"""
    

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

    The version of the OpenAPI document: 
    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
from typing import Any, ClassVar, Dict, List, Optional
from goodmem._generated.models.abstract_reply import AbstractReply
from goodmem._generated.models.good_mem_status import GoodMemStatus
from goodmem._generated.models.memory import Memory
from goodmem._generated.models.result_set_boundary import ResultSetBoundary
from goodmem._generated.models.retrieved_item import RetrievedItem
from typing import Optional, Set
from typing_extensions import Self

class RetrieveMemoryEvent(BaseModel):
    """
    Streaming event from memory retrieval operation
    """ # noqa: E501
    result_set_boundary: Optional[ResultSetBoundary] = Field(default=None, alias="resultSetBoundary")
    abstract_reply: Optional[AbstractReply] = Field(default=None, alias="abstractReply")
    retrieved_item: Optional[RetrievedItem] = Field(default=None, alias="retrievedItem")
    memory_definition: Optional[Memory] = Field(default=None, alias="memoryDefinition")
    status: Optional[GoodMemStatus] = None
    __properties: ClassVar[List[str]] = ["resultSetBoundary", "abstractReply", "retrievedItem", "memoryDefinition", "status"]

    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 RetrieveMemoryEvent 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 result_set_boundary
        if self.result_set_boundary:
            _dict['resultSetBoundary'] = self.result_set_boundary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of abstract_reply
        if self.abstract_reply:
            _dict['abstractReply'] = self.abstract_reply.to_dict()
        # override the default output from pydantic by calling `to_dict()` of retrieved_item
        if self.retrieved_item:
            _dict['retrievedItem'] = self.retrieved_item.to_dict()
        # override the default output from pydantic by calling `to_dict()` of memory_definition
        if self.memory_definition:
            _dict['memoryDefinition'] = self.memory_definition.to_dict()
        # override the default output from pydantic by calling `to_dict()` of status
        if self.status:
            _dict['status'] = self.status.to_dict()
        # set to None if result_set_boundary (nullable) is None
        # and model_fields_set contains the field
        if self.result_set_boundary is None and "result_set_boundary" in self.model_fields_set:
            _dict['resultSetBoundary'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "resultSetBoundary": ResultSetBoundary.from_dict(obj["resultSetBoundary"]) if obj.get("resultSetBoundary") is not None else None,
            "abstractReply": AbstractReply.from_dict(obj["abstractReply"]) if obj.get("abstractReply") is not None else None,
            "retrievedItem": RetrievedItem.from_dict(obj["retrievedItem"]) if obj.get("retrievedItem") is not None else None,
            "memoryDefinition": Memory.from_dict(obj["memoryDefinition"]) if obj.get("memoryDefinition") is not None else None,
            "status": GoodMemStatus.from_dict(obj["status"]) if obj.get("status") is not None else None
        })
        return _obj


