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

class MemoryCreationRequest(BaseModel):
    """
    Request body for creating a new Memory. A Memory represents content stored in a space.
    """ # noqa: E501
    memory_id: Optional[StrictStr] = Field(default=None, description="Optional client-provided UUID for the memory. If omitted, the server generates one. Returns ALREADY_EXISTS if the ID is already in use.", alias="memoryId")
    space_id: StrictStr = Field(description="ID of the space where this memory will be stored", alias="spaceId")
    original_content: Optional[StrictStr] = Field(default=None, description="Original content as plain text (use either this or originalContentB64)", alias="originalContent")
    original_content_b64: Optional[StrictStr] = Field(default=None, description="Original content as base64-encoded binary data (use either this or originalContent)", alias="originalContentB64")
    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")
    metadata: Optional[Dict[str, Any]] = Field(default=None, description="Additional metadata for the memory")
    chunking_config: Optional[ChunkingConfiguration] = Field(default=None, alias="chunkingConfig")
    file_field: Optional[StrictStr] = Field(default=None, description="Optional multipart file field name to bind binary content; required when multiple files are uploaded in a batch multipart request.", alias="fileField")
    __properties: ClassVar[List[str]] = ["memoryId", "spaceId", "originalContent", "originalContentB64", "originalContentRef", "contentType", "metadata", "chunkingConfig", "fileField"]

    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 MemoryCreationRequest 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()
        # set to None if memory_id (nullable) is None
        # and model_fields_set contains the field
        if self.memory_id is None and "memory_id" in self.model_fields_set:
            _dict['memoryId'] = None

        # 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_b64 (nullable) is None
        # and model_fields_set contains the field
        if self.original_content_b64 is None and "original_content_b64" in self.model_fields_set:
            _dict['originalContentB64'] = 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 file_field (nullable) is None
        # and model_fields_set contains the field
        if self.file_field is None and "file_field" in self.model_fields_set:
            _dict['fileField'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of MemoryCreationRequest 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"),
            "originalContentB64": obj.get("originalContentB64"),
            "originalContentRef": obj.get("originalContentRef"),
            "contentType": obj.get("contentType"),
            "metadata": obj.get("metadata"),
            "chunkingConfig": ChunkingConfiguration.from_dict(obj["chunkingConfig"]) if obj.get("chunkingConfig") is not None else None,
            "fileField": obj.get("fileField")
        })
        return _obj


