# 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, StrictBytes, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union
from goodmem._generated.models.chunking_configuration import ChunkingConfiguration
from goodmem._generated.models.processing_history import ProcessingHistory
from typing import Optional, Set
from typing_extensions import Self

class Memory(BaseModel):
    """
    Memory object containing stored content and metadata
    """ # noqa: E501
    memory_id: StrictStr = Field(description="Unique identifier of the memory", alias="memoryId")
    space_id: StrictStr = Field(description="ID of the space containing this memory", alias="spaceId")
    original_content: Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]] = Field(default=None, description="Original content (only included if requested)", alias="originalContent")
    original_content_length: Optional[StrictInt] = Field(default=None, description="Size in bytes of the inline original content", alias="originalContentLength")
    original_content_sha256: Optional[StrictStr] = Field(default=None, description="SHA-256 digest of the inline original content, hex encoded", alias="originalContentSha256")
    original_content_ref: Optional[StrictStr] = Field(default=None, description="Reference to external content location", alias="originalContentRef")
    content_type: StrictStr = Field(description="MIME type of the content", alias="contentType")
    processing_status: StrictStr = Field(description="Processing status of the memory", alias="processingStatus")
    page_image_status: Optional[StrictStr] = Field(default=None, description="Processing status of page-image extraction for this memory", alias="pageImageStatus")
    page_image_count: Optional[StrictInt] = Field(default=None, description="Number of extracted page-image renditions linked to this memory", alias="pageImageCount")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional metadata for the memory")
    created_at: StrictInt = Field(description="Timestamp when the memory was created (milliseconds since epoch)", alias="createdAt")
    updated_at: StrictInt = Field(description="Timestamp when the memory was last updated (milliseconds since epoch)", alias="updatedAt")
    created_by_id: StrictStr = Field(description="ID of the user who created this memory", alias="createdById")
    updated_by_id: StrictStr = Field(description="ID of the user who last updated this memory", alias="updatedById")
    chunking_config: Optional[ChunkingConfiguration] = Field(default=None, alias="chunkingConfig")
    processing_history: Optional[ProcessingHistory] = Field(default=None, alias="processingHistory")
    __properties: ClassVar[List[str]] = ["memoryId", "spaceId", "originalContent", "originalContentLength", "originalContentSha256", "originalContentRef", "contentType", "processingStatus", "pageImageStatus", "pageImageCount", "metadata", "createdAt", "updatedAt", "createdById", "updatedById", "chunkingConfig", "processingHistory"]



    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 Memory 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 chunking_config
        if self.chunking_config:
            _dict['chunkingConfig'] = self.chunking_config.to_dict()
        # override the default output from pydantic by calling `to_dict()` of processing_history
        if self.processing_history:
            _dict['processingHistory'] = self.processing_history.to_dict()
        # set to None if original_content (nullable) is None
        # and model_fields_set contains the field
        if self.original_content is None and "original_content" in self.model_fields_set:
            _dict['originalContent'] = None

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "memoryId": obj.get("memoryId"),
            "spaceId": obj.get("spaceId"),
            "originalContent": obj.get("originalContent"),
            "originalContentLength": obj.get("originalContentLength"),
            "originalContentSha256": obj.get("originalContentSha256"),
            "originalContentRef": obj.get("originalContentRef"),
            "contentType": obj.get("contentType"),
            "processingStatus": obj.get("processingStatus"),
            "pageImageStatus": obj.get("pageImageStatus"),
            "pageImageCount": obj.get("pageImageCount"),
            "metadata": obj.get("metadata"),
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "createdById": obj.get("createdById"),
            "updatedById": obj.get("updatedById"),
            "chunkingConfig": ChunkingConfiguration.from_dict(obj["chunkingConfig"]) if obj.get("chunkingConfig") is not None else None,
            "processingHistory": ProcessingHistory.from_dict(obj["processingHistory"]) if obj.get("processingHistory") is not None else None
        })
        return _obj


