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

class SpaceCreationRequest(BaseModel):
    """
    Request body for creating a new Space. A Space is a container for organizing related memories with vector embeddings.
    """ # noqa: E501
    name: StrictStr = Field(description="The desired name for the space. Must be unique within the user's scope.")
    labels: Optional[Dict[str, StrictStr]] = Field(default=None, description="A set of key-value pairs to categorize or tag the space. Used for filtering and organizational purposes.")
    space_embedders: Optional[List[SpaceEmbedderConfig]] = Field(default=None, description="List of embedder configurations to associate with this space. Each specifies an embedder ID and a relative default retrieval weight used when no per-request overrides are provided.", alias="spaceEmbedders")
    public_read: Optional[StrictBool] = Field(default=None, description="Indicates if the space and its memories can be read by unauthenticated users or users other than the owner. Defaults to false.", alias="publicRead")
    owner_id: Optional[StrictStr] = Field(default=None, description="Optional owner ID. If not provided, derived from the authentication context. Requires CREATE_SPACE_ANY permission if specified.", alias="ownerId")
    default_chunking_config: ChunkingConfiguration = Field(alias="defaultChunkingConfig")
    space_id: Optional[StrictStr] = Field(default=None, description="Optional client-provided UUID for idempotent creation. If not provided, server generates a new UUID. Returns ALREADY_EXISTS if ID is already in use.", alias="spaceId")
    __properties: ClassVar[List[str]] = ["name", "labels", "spaceEmbedders", "publicRead", "ownerId", "defaultChunkingConfig", "spaceId"]

    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 SpaceCreationRequest 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

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

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

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

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

        return _dict

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

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

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


