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

class Space(BaseModel):
    """
    A Space is a container for organizing related memories with vector embeddings.
    """ # noqa: E501
    space_id: StrictStr = Field(description="The unique identifier for this space.", alias="spaceId")
    name: StrictStr = Field(description="The name of the space.")
    labels: Optional[Dict[str, StrictStr]] = Field(default=None, description="Key-value pairs of metadata associated with the space.")
    space_embedders: List[SpaceEmbedder] = Field(description="The list of embedders associated with this space.", alias="spaceEmbedders")
    created_at: StrictInt = Field(description="Timestamp when this space was created (milliseconds since epoch).", alias="createdAt")
    updated_at: StrictInt = Field(description="Timestamp when this space was last updated (milliseconds since epoch).", alias="updatedAt")
    owner_id: StrictStr = Field(description="The ID of the user who owns this space.", alias="ownerId")
    created_by_id: StrictStr = Field(description="The ID of the user who created this space.", alias="createdById")
    updated_by_id: StrictStr = Field(description="The ID of the user who last updated this space.", alias="updatedById")
    public_read: StrictBool = Field(description="Whether this space is publicly readable by all users.", alias="publicRead")
    default_chunking_config: Optional[ChunkingConfiguration] = Field(default=None, alias="defaultChunkingConfig")
    __properties: ClassVar[List[str]] = ["spaceId", "name", "labels", "spaceEmbedders", "createdAt", "updatedAt", "ownerId", "createdById", "updatedById", "publicRead", "defaultChunkingConfig"]

    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 Space 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 each item in space_embedders (list)
        _items = []
        if self.space_embedders:
            for _item_space_embedders in self.space_embedders:
                if _item_space_embedders:
                    _items.append(_item_space_embedders.to_dict())
            _dict['spaceEmbedders'] = _items
        # override the default output from pydantic by calling `to_dict()` of default_chunking_config
        if self.default_chunking_config:
            _dict['defaultChunkingConfig'] = self.default_chunking_config.to_dict()
        # set to None if labels (nullable) is None
        # and model_fields_set contains the field
        if self.labels is None and "labels" in self.model_fields_set:
            _dict['labels'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "spaceId": obj.get("spaceId"),
            "name": obj.get("name"),
            "labels": obj.get("labels"),
            "spaceEmbedders": [SpaceEmbedder.from_dict(_item) for _item in obj["spaceEmbedders"]] if obj.get("spaceEmbedders") is not None else None,
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "ownerId": obj.get("ownerId"),
            "createdById": obj.get("createdById"),
            "updatedById": obj.get("updatedById"),
            "publicRead": obj.get("publicRead"),
            "defaultChunkingConfig": ChunkingConfiguration.from_dict(obj["defaultChunkingConfig"]) if obj.get("defaultChunkingConfig") is not None else None
        })
        return _obj


