# DO NOT EDIT — generated by _client_gen/convenience_emitter.py from convenience.json.
# Regenerate with: cd clients/v2 && python -c "from _client_gen.convenience_emitter import generate_convenience; generate_convenience()"

"""Memories API namespace — generated from convenience.json."""

from __future__ import annotations

from typing import Any, List, Literal, overload

from goodmem._api_base.memories import MemoriesAPIBase, AsyncMemoriesAPIBase


# --- Convenience imports ---
from goodmem._transforms import apply_convenience_transforms
from goodmem._transforms import _transform_list_kwargs
from goodmem._overrides import (
    memories_create_sync,
    memories_create_async,
    MemoryCreationRequest,
    memories_batch_create_sync,
    memories_batch_create_async,
    memories_retrieve_sync,
    memories_retrieve_async,
)
from goodmem.models.batch_memory_response import BatchMemoryResponse
from goodmem.models.chunking_configuration import ChunkingConfiguration
from goodmem.models.context_item import ContextItem
from goodmem.models.hnsw_options import HnswOptions
from goodmem.models.memory import Memory
from goodmem.models.post_processor import PostProcessor
from goodmem.models.retrieve_memory_event import RetrieveMemoryEvent
from goodmem.models.sort_order import SortOrder
from goodmem.models.space_key import SpaceKey
from goodmem.pagination import AsyncPage, Page
from goodmem.streaming import AsyncRetrieveMemoryStream, RetrieveMemoryStream


class MemoriesAPI(MemoriesAPIBase):
    def batch_create(self, *, requests: list[MemoryCreationRequest]) -> BatchMemoryResponse:
        return memories_batch_create_sync(self, requests=requests)

    def create(self, *, space_id: str, chunking_config: ChunkingConfiguration | None = None, content_type: str | None = None, extract_page_images: bool | None = None, memory_id: str | None = None, metadata: dict | None = None, original_content: str | None = None, original_content_b64: str | None = None, original_content_ref: str | None = None, file_path: str | None = None) -> Memory:
        _kw: dict[str, Any] = {"space_id": space_id}
        if chunking_config is not None: _kw["chunking_config"] = chunking_config
        if content_type is not None: _kw["content_type"] = content_type
        if extract_page_images is not None: _kw["extract_page_images"] = extract_page_images
        if memory_id is not None: _kw["memory_id"] = memory_id
        if metadata is not None: _kw["metadata"] = metadata
        if original_content is not None: _kw["original_content"] = original_content
        if original_content_b64 is not None: _kw["original_content_b64"] = original_content_b64
        if original_content_ref is not None: _kw["original_content_ref"] = original_content_ref
        return memories_create_sync(self, file_path=file_path, **_kw)

    def list(self, *, space_id: str, filter: str | None = None, include_content: bool | None = False, include_processing_history: bool | None = False, sort_by: str | None = None, sort_order: SortOrder | None = None, status_filter: str | None = None, page_size: int | None = None, max_items: int | None = None, next_token: str | None = None) -> Page[Memory]:
        _kw: dict[str, Any] = {"space_id": space_id}
        if filter is not None: _kw["filter"] = filter
        if include_content is not None: _kw["include_content"] = include_content
        if include_processing_history is not None: _kw["include_processing_history"] = include_processing_history
        if sort_by is not None: _kw["sort_by"] = sort_by
        if sort_order is not None: _kw["sort_order"] = sort_order
        if status_filter is not None: _kw["status_filter"] = status_filter
        if page_size is not None: _kw["page_size"] = page_size
        if max_items is not None: _kw["max_items"] = max_items
        if next_token is not None: _kw["next_token"] = next_token
        max_items_val = _transform_list_kwargs(_kw)
        page = super().list(**_kw)
        if max_items_val is not None:
            page._max_items = max_items_val
            page.data = page.data[:max_items_val]
        return page

    @overload
    def retrieve(self, *, message: str, chronological_resort: bool | None = True, context: list[ContextItem] | None = None, fetch_memory: bool | None = True, fetch_memory_content: bool | None = False, gen_token_budget: int | None = 512, hnsw: HnswOptions | None = None, llm_id: str | None = None, llm_temp: float | None = 0.3, max_results: int | None = 10, post_processor: PostProcessor | None = None, prompt: str | None = None, relevance_threshold: float | None = None, requested_size: int | None = None, reranker_id: str | None = None, space_ids: list[str] | None = None, space_keys: list[SpaceKey] | None = None, sys_prompt: str | None = None, stream: Literal[True] = ...) -> RetrieveMemoryStream: ...
    @overload
    def retrieve(self, *, message: str, chronological_resort: bool | None = True, context: list[ContextItem] | None = None, fetch_memory: bool | None = True, fetch_memory_content: bool | None = False, gen_token_budget: int | None = 512, hnsw: HnswOptions | None = None, llm_id: str | None = None, llm_temp: float | None = 0.3, max_results: int | None = 10, post_processor: PostProcessor | None = None, prompt: str | None = None, relevance_threshold: float | None = None, requested_size: int | None = None, reranker_id: str | None = None, space_ids: list[str] | None = None, space_keys: list[SpaceKey] | None = None, sys_prompt: str | None = None, stream: Literal[False]) -> List[RetrieveMemoryEvent]: ...
    def retrieve(self, *, message: str, chronological_resort: bool | None = True, context: list[ContextItem] | None = None, fetch_memory: bool | None = True, fetch_memory_content: bool | None = False, gen_token_budget: int | None = 512, hnsw: HnswOptions | None = None, llm_id: str | None = None, llm_temp: float | None = 0.3, max_results: int | None = 10, post_processor: PostProcessor | None = None, prompt: str | None = None, relevance_threshold: float | None = None, requested_size: int | None = None, reranker_id: str | None = None, space_ids: list[str] | None = None, space_keys: list[SpaceKey] | None = None, sys_prompt: str | None = None, stream: bool = True) -> RetrieveMemoryStream | List[RetrieveMemoryEvent]:
        _kw: dict[str, Any] = {"message": message}
        if chronological_resort is not None: _kw["chronological_resort"] = chronological_resort
        if context is not None: _kw["context"] = context
        if fetch_memory is not None: _kw["fetch_memory"] = fetch_memory
        if fetch_memory_content is not None: _kw["fetch_memory_content"] = fetch_memory_content
        if gen_token_budget is not None: _kw["gen_token_budget"] = gen_token_budget
        if hnsw is not None: _kw["hnsw"] = hnsw
        if llm_id is not None: _kw["llm_id"] = llm_id
        if llm_temp is not None: _kw["llm_temp"] = llm_temp
        if max_results is not None: _kw["max_results"] = max_results
        if post_processor is not None: _kw["post_processor"] = post_processor
        if prompt is not None: _kw["prompt"] = prompt
        if relevance_threshold is not None: _kw["relevance_threshold"] = relevance_threshold
        if requested_size is not None: _kw["requested_size"] = requested_size
        if reranker_id is not None: _kw["reranker_id"] = reranker_id
        if space_ids is not None: _kw["space_ids"] = space_ids
        if space_keys is not None: _kw["space_keys"] = space_keys
        if sys_prompt is not None: _kw["sys_prompt"] = sys_prompt
        return memories_retrieve_sync(self, stream=stream, **_kw)



class AsyncMemoriesAPI(AsyncMemoriesAPIBase):
    async def batch_create(self, *, requests: list[MemoryCreationRequest]) -> BatchMemoryResponse:
        return await memories_batch_create_async(self, requests=requests)

    async def create(self, *, space_id: str, chunking_config: ChunkingConfiguration | None = None, content_type: str | None = None, extract_page_images: bool | None = None, memory_id: str | None = None, metadata: dict | None = None, original_content: str | None = None, original_content_b64: str | None = None, original_content_ref: str | None = None, file_path: str | None = None) -> Memory:
        _kw: dict[str, Any] = {"space_id": space_id}
        if chunking_config is not None: _kw["chunking_config"] = chunking_config
        if content_type is not None: _kw["content_type"] = content_type
        if extract_page_images is not None: _kw["extract_page_images"] = extract_page_images
        if memory_id is not None: _kw["memory_id"] = memory_id
        if metadata is not None: _kw["metadata"] = metadata
        if original_content is not None: _kw["original_content"] = original_content
        if original_content_b64 is not None: _kw["original_content_b64"] = original_content_b64
        if original_content_ref is not None: _kw["original_content_ref"] = original_content_ref
        return await memories_create_async(self, file_path=file_path, **_kw)

    async def list(self, *, space_id: str, filter: str | None = None, include_content: bool | None = False, include_processing_history: bool | None = False, sort_by: str | None = None, sort_order: SortOrder | None = None, status_filter: str | None = None, page_size: int | None = None, max_items: int | None = None, next_token: str | None = None) -> AsyncPage[Memory]:
        _kw: dict[str, Any] = {"space_id": space_id}
        if filter is not None: _kw["filter"] = filter
        if include_content is not None: _kw["include_content"] = include_content
        if include_processing_history is not None: _kw["include_processing_history"] = include_processing_history
        if sort_by is not None: _kw["sort_by"] = sort_by
        if sort_order is not None: _kw["sort_order"] = sort_order
        if status_filter is not None: _kw["status_filter"] = status_filter
        if page_size is not None: _kw["page_size"] = page_size
        if max_items is not None: _kw["max_items"] = max_items
        if next_token is not None: _kw["next_token"] = next_token
        max_items_val = _transform_list_kwargs(_kw)
        page = await super().list(**_kw)
        if max_items_val is not None:
            page._max_items = max_items_val
            page.data = page.data[:max_items_val]
        return page

    @overload
    async def retrieve(self, *, message: str, chronological_resort: bool | None = True, context: list[ContextItem] | None = None, fetch_memory: bool | None = True, fetch_memory_content: bool | None = False, gen_token_budget: int | None = 512, hnsw: HnswOptions | None = None, llm_id: str | None = None, llm_temp: float | None = 0.3, max_results: int | None = 10, post_processor: PostProcessor | None = None, prompt: str | None = None, relevance_threshold: float | None = None, requested_size: int | None = None, reranker_id: str | None = None, space_ids: list[str] | None = None, space_keys: list[SpaceKey] | None = None, sys_prompt: str | None = None, stream: Literal[True] = ...) -> AsyncRetrieveMemoryStream: ...
    @overload
    async def retrieve(self, *, message: str, chronological_resort: bool | None = True, context: list[ContextItem] | None = None, fetch_memory: bool | None = True, fetch_memory_content: bool | None = False, gen_token_budget: int | None = 512, hnsw: HnswOptions | None = None, llm_id: str | None = None, llm_temp: float | None = 0.3, max_results: int | None = 10, post_processor: PostProcessor | None = None, prompt: str | None = None, relevance_threshold: float | None = None, requested_size: int | None = None, reranker_id: str | None = None, space_ids: list[str] | None = None, space_keys: list[SpaceKey] | None = None, sys_prompt: str | None = None, stream: Literal[False]) -> List[RetrieveMemoryEvent]: ...
    async def retrieve(self, *, message: str, chronological_resort: bool | None = True, context: list[ContextItem] | None = None, fetch_memory: bool | None = True, fetch_memory_content: bool | None = False, gen_token_budget: int | None = 512, hnsw: HnswOptions | None = None, llm_id: str | None = None, llm_temp: float | None = 0.3, max_results: int | None = 10, post_processor: PostProcessor | None = None, prompt: str | None = None, relevance_threshold: float | None = None, requested_size: int | None = None, reranker_id: str | None = None, space_ids: list[str] | None = None, space_keys: list[SpaceKey] | None = None, sys_prompt: str | None = None, stream: bool = True) -> AsyncRetrieveMemoryStream | List[RetrieveMemoryEvent]:
        _kw: dict[str, Any] = {"message": message}
        if chronological_resort is not None: _kw["chronological_resort"] = chronological_resort
        if context is not None: _kw["context"] = context
        if fetch_memory is not None: _kw["fetch_memory"] = fetch_memory
        if fetch_memory_content is not None: _kw["fetch_memory_content"] = fetch_memory_content
        if gen_token_budget is not None: _kw["gen_token_budget"] = gen_token_budget
        if hnsw is not None: _kw["hnsw"] = hnsw
        if llm_id is not None: _kw["llm_id"] = llm_id
        if llm_temp is not None: _kw["llm_temp"] = llm_temp
        if max_results is not None: _kw["max_results"] = max_results
        if post_processor is not None: _kw["post_processor"] = post_processor
        if prompt is not None: _kw["prompt"] = prompt
        if relevance_threshold is not None: _kw["relevance_threshold"] = relevance_threshold
        if requested_size is not None: _kw["requested_size"] = requested_size
        if reranker_id is not None: _kw["reranker_id"] = reranker_id
        if space_ids is not None: _kw["space_ids"] = space_ids
        if space_keys is not None: _kw["space_keys"] = space_keys
        if sys_prompt is not None: _kw["sys_prompt"] = sys_prompt
        return await memories_retrieve_async(self, stream=stream, **_kw)

