# DO NOT EDIT — generated by _gen/ from the OpenAPI spec.
# Regenerate with: ./client_gen.sh
from __future__ import annotations

from typing import Any

import httpx

from goodmem._base import _op_meta, _expand_label_filters
from goodmem._base import _op_meta, _prepare_create_payload
from goodmem.errors import raise_for_status
from goodmem.models.endpoint_authentication import EndpointAuthentication
from goodmem.models.list_rerankers_response import ListRerankersResponse
from goodmem.models.provider_type import ProviderType
from goodmem.models.reranker_creation_request import RerankerCreationRequest
from goodmem.models.reranker_response import RerankerResponse
from goodmem.models.update_reranker_request import UpdateRerankerRequest


class RerankersAPIBase:
    """Rerankers API — auto-generated structural base.

    Auto-generated structural base. Do not edit.
    Override in goodmem/api/rerankers.py to add domain-specific logic.
    """

    _create_model = RerankerCreationRequest
    _rest_metadata: dict = {'create': {'http_method': 'POST', 'path': '/v1/rerankers', 'input_shape': 'kwargs_body', 'summary': 'Create a new reranker', 'description': "Creates a new reranker configuration for ranking search results. Rerankers represent connections to different reranking API services (like TEI, OpenAI, etc.) and include all the necessary configuration to use them for result ranking. DUPLICATE DETECTION: Returns HTTP 409 Conflict (ALREADY_EXISTS) if another reranker exists with identical {ownerId, providerType, endpointUrl, apiPath, modelIdentifier, credentialsFingerprint} after URL canonicalization. Uniqueness is enforced per-owner, allowing different users to have identical configurations. Credentials are hashed (SHA-256) for uniqueness while remaining encrypted. DEFAULTS: apiPath defaults to '/v2/rerank' for Cohere and '/rerank' for other providers if omitted; supportedModalities defaults to [TEXT] if omitted. Requires CREATE_RERANKER_OWN permission (or CREATE_RERANKER_ANY for admin users). This operation is NOT idempotent - each request creates a new reranker record.", 'response': 'RerankerResponse', 'params': [{'name': 'display_name', 'type': 'str', 'source': 'body', 'required': True, 'alias': 'displayName', 'description': 'User-facing name of the reranker'}, {'name': 'description', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Description of the reranker'}, {'name': 'provider_type', 'type': 'ProviderType', 'source': 'body', 'required': True, 'alias': 'providerType', 'description': 'Type of reranking provider'}, {'name': 'endpoint_url', 'type': 'str', 'source': 'body', 'required': True, 'alias': 'endpointUrl', 'description': 'API endpoint URL'}, {'name': 'api_path', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'apiPath', 'description': 'API path for reranking request (defaults: Cohere /v2/rerank, Jina /v1/rerank, others /rerank)'}, {'name': 'model_identifier', 'type': 'str', 'source': 'body', 'required': True, 'alias': 'modelIdentifier', 'description': 'Model identifier'}, {'name': 'supported_modalities', 'type': 'list[Modality]', 'source': 'body', 'required': False, 'alias': 'supportedModalities', 'description': 'Supported content modalities (defaults to TEXT if not provided)', 'default': ['TEXT']}, {'name': 'credentials', 'type': 'EndpointAuthentication', 'source': 'body', 'required': False, 'description': 'Structured credential payload describing how to authenticate with the provider. Required for SaaS providers; optional for local deployments.'}, {'name': 'labels', 'type': 'dict', 'source': 'body', 'required': False, 'description': 'User-defined labels for categorization'}, {'name': 'version', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Version information'}, {'name': 'monitoring_endpoint', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'monitoringEndpoint', 'description': 'Monitoring endpoint URL'}, {'name': 'owner_id', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'ownerId', 'description': 'Optional owner ID. If not provided, derived from the authentication context. Requires CREATE_RERANKER_ANY permission if specified.'}, {'name': 'reranker_id', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'rerankerId', '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.'}], 'body_model': 'RerankerCreationRequest', 'body_expr': 'RerankerCreationRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'get': {'http_method': 'GET', 'path': '/v1/rerankers/{id}', 'input_shape': 'path_query', 'summary': 'Get a reranker by ID', 'description': 'Retrieves the details of a specific reranker configuration by its unique identifier. Response payloads include stored credentials, matching gRPC response semantics. Requires READ_RERANKER_OWN permission for rerankers you own (or READ_RERANKER_ANY for admin users). This is a read-only operation with no side effects and is safe to retry.', 'response': 'RerankerResponse', 'query_params': ['id'], 'params': [{'name': 'id', 'type': 'str', 'source': 'path', 'required': True, 'description': 'The unique identifier of the reranker to retrieve'}]}, 'list': {'http_method': 'GET', 'path': '/v1/rerankers', 'input_shape': 'query_only', 'summary': 'List rerankers', 'description': 'Retrieves a list of reranker configurations accessible to the caller, with optional filtering. IMPORTANT: Pagination is NOT supported - all matching results are returned. Results are ordered by created_at descending. Responses include stored credentials, matching gRPC response semantics. LABEL FILTERS: Supply dynamic query parameters in the form label.<key>=<value> (for example, label.environment=production). PERMISSION-BASED FILTERING: With LIST_RERANKER_OWN permission, only your own rerankers are shown. With LIST_RERANKER_ANY permission, you can see all rerankers or filter by any ownerId. Specifying ownerId without LIST_RERANKER_ANY permission returns PERMISSION_DENIED.', 'response': 'ListRerankersResponse', 'query_params': ['owner_id', 'provider_type', 'label.*'], 'params': [{'name': 'owner_id', 'type': 'str', 'source': 'query', 'required': False, 'alias': 'ownerId', 'description': 'Filter rerankers by owner ID. With LIST_RERANKER_ANY permission, omitting this shows all accessible rerankers; providing it filters by that owner. With LIST_RERANKER_OWN permission, only your own rerankers are shown regardless of this parameter (PERMISSION_DENIED if set to another user).'}, {'name': 'provider_type', 'type': 'ProviderType', 'source': 'query', 'required': False, 'alias': 'providerType', 'description': 'Filter rerankers by provider type. Allowed values match the ProviderType schema.'}, {'name': 'label.*', 'type': 'str', 'source': 'query', 'required': False, 'description': 'Filter by label value. Multiple label filters can be specified (e.g., ?label.environment=production&label.team=search)'}], 'supports_label_wildcard': True}, 'update': {'http_method': 'PUT', 'path': '/v1/rerankers/{id}', 'input_shape': 'typed_request', 'summary': 'Update a reranker', 'description': 'Updates an existing reranker configuration including display information, endpoint configuration, model parameters, credentials, and labels. All fields are optional - only specified fields will be updated. IMMUTABLE FIELDS: providerType and ownerId cannot be changed after creation. SUPPORTED_MODALITIES UPDATE: If the array contains ≥1 elements, it replaces the stored set; if empty or omitted, no change occurs. Returns ALREADY_EXISTS if update would create duplicate with same {ownerId, providerType, endpointUrl, apiPath, modelIdentifier, credentialsFingerprint} after URL canonicalization (HTTP 409 Conflict / ALREADY_EXISTS). Requires UPDATE_RERANKER_OWN permission for rerankers you own (or UPDATE_RERANKER_ANY for admin users). This operation is idempotent.', 'response': 'RerankerResponse', 'query_params': ['id'], 'params': [{'name': 'id', 'type': 'str', 'source': 'path', 'required': True, 'description': 'The unique identifier of the reranker to update'}, {'name': 'display_name', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'displayName', 'description': 'User-facing name of the reranker'}, {'name': 'description', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Description of the reranker'}, {'name': 'endpoint_url', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'endpointUrl', 'description': 'API endpoint URL'}, {'name': 'api_path', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'apiPath', 'description': 'API path for reranking request'}, {'name': 'model_identifier', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'modelIdentifier', 'description': 'Model identifier'}, {'name': 'supported_modalities', 'type': 'list[Modality]', 'source': 'body', 'required': False, 'alias': 'supportedModalities', 'description': 'Supported content modalities'}, {'name': 'credentials', 'type': 'EndpointAuthentication', 'source': 'body', 'required': False, 'description': 'Structured credential payload describing how to authenticate with the provider. Omit to keep existing credentials.'}, {'name': 'replace_labels', 'type': 'dict', 'source': 'body', 'required': False, 'alias': 'replaceLabels', 'description': 'Replace all existing labels with these (mutually exclusive with mergeLabels)'}, {'name': 'merge_labels', 'type': 'dict', 'source': 'body', 'required': False, 'alias': 'mergeLabels', 'description': 'Merge these labels with existing ones (mutually exclusive with replaceLabels)'}, {'name': 'version', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Version information'}, {'name': 'monitoring_endpoint', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'monitoringEndpoint', 'description': 'Monitoring endpoint URL'}], 'body_model': 'UpdateRerankerRequest', 'body_expr': 'UpdateRerankerRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'delete': {'http_method': 'DELETE', 'path': '/v1/rerankers/{id}', 'input_shape': 'path_query', 'summary': 'Delete a reranker', 'description': 'Permanently deletes a reranker configuration. This operation cannot be undone and immediately removes the reranker record from the database. SIDE EFFECTS: Invalidates any cached references to this reranker; does not affect historical usage data or audit logs. Requires DELETE_RERANKER_OWN permission for rerankers you own (or DELETE_RERANKER_ANY for admin users). This operation is safe to retry - may return NOT_FOUND if already deleted.', 'response': 'None', 'query_params': ['id'], 'params': [{'name': 'id', 'type': 'str', 'source': 'path', 'required': True, 'description': 'The unique identifier of the reranker to delete'}]}}

    def __init__(self, http: httpx.Client, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    def create(self, *, display_name: str | None=None, description: str | None=None, provider_type: ProviderType | None=None, endpoint_url: str | None=None, api_path: str | None=None, model_identifier: str | None=None, supported_modalities: list | None=('TEXT',), credentials: EndpointAuthentication | None=None, labels: dict | None=None, version: str | None=None, monitoring_endpoint: str | None=None, owner_id: str | None=None, reranker_id: str | None=None) -> RerankerResponse:
        """Create a new reranker

        Creates a new reranker configuration for ranking search results. Rerankers represent connections to different reranking API services (like TEI, OpenAI, etc.) and include all the necessary configuration to use them for result ranking. DUPLICATE DETECTION: Returns HTTP 409 Conflict (ALREADY_EXISTS) if another reranker exists with identical {owner_id, provider_type, endpoint_url, api_path, model_identifier, credentials_fingerprint} after URL canonicalization. Uniqueness is enforced per-owner, allowing different users to have identical configurations. Credentials are hashed (SHA-256) for uniqueness while remaining encrypted. DEFAULTS: api_path defaults to '/v2/rerank' for Cohere and '/rerank' for other providers if omitted; supported_modalities defaults to [TEXT] if omitted. Requires CREATE_RERANKER_OWN permission (or CREATE_RERANKER_ANY for admin users). This operation is NOT idempotent - each request creates a new reranker record.

        Args:
            display_name (str): User-facing name of the reranker
            description (str, optional): Description of the reranker
            provider_type (ProviderType): Type of reranking provider
            endpoint_url (str): API endpoint URL
            api_path (str, optional): API path for reranking request (defaults: Cohere /v2/rerank, Jina /v1/rerank, others /rerank)
            model_identifier (str): Model identifier
            supported_modalities (list, optional, default=['TEXT']): Supported content modalities (defaults to TEXT if not provided)
            credentials (EndpointAuthentication, optional): Structured credential payload describing how to authenticate with the provider. Required for SaaS providers; optional for local deployments.
            labels (dict, optional): User-defined labels for categorization
            version (str, optional): Version information
            monitoring_endpoint (str, optional): Monitoring endpoint URL
            owner_id (str, optional): Optional owner ID. If not provided, derived from the authentication context. Requires CREATE_RERANKER_ANY permission if specified.
            reranker_id (str, optional): Optional client-provided UUID for idempotent creation. If not provided, server generates a new UUID. Returns ALREADY_EXISTS if ID is already in use.

        Returns:
            RerankerResponse
        """
        op = _op_meta(self, 'create')
        _params: dict = {}
        if display_name is not None:
            _params['display_name'] = display_name
        if description is not None:
            _params['description'] = description
        if provider_type is not None:
            _params['provider_type'] = provider_type
        if endpoint_url is not None:
            _params['endpoint_url'] = endpoint_url
        if api_path is not None:
            _params['api_path'] = api_path
        if model_identifier is not None:
            _params['model_identifier'] = model_identifier
        _params['supported_modalities'] = supported_modalities
        if credentials is not None:
            _params['credentials'] = credentials
        if labels is not None:
            _params['labels'] = labels
        if version is not None:
            _params['version'] = version
        if monitoring_endpoint is not None:
            _params['monitoring_endpoint'] = monitoring_endpoint
        if owner_id is not None:
            _params['owner_id'] = owner_id
        if reranker_id is not None:
            _params['reranker_id'] = reranker_id
        json_payload, data_payload, files_payload = _prepare_create_payload(
            create_model=RerankerCreationRequest, op=op, kwargs=_params,
        )
        resp = self._http.post(
            "/v1/rerankers",
            json=json_payload,
            data=data_payload,
            files=files_payload,
            headers=self._headers,
        )
        raise_for_status(resp)
        return RerankerResponse.model_validate(resp.json())

    def list(self, *, labels: dict[str, str] | None = None, owner_id: str | None=None, provider_type: ProviderType | None=None) -> list[RerankerResponse]:
        """List rerankers

        Retrieves a list of reranker configurations accessible to the caller, with optional filtering. IMPORTANT: Pagination is NOT supported - all matching results are returned. Results are ordered by created_at descending. Responses include stored credentials, matching gRPC response semantics. LABEL FILTERS: Supply dynamic query parameters in the form label.<key>=<value> (for example, label.environment=production). PERMISSION-BASED FILTERING: With LIST_RERANKER_OWN permission, only your own rerankers are shown. With LIST_RERANKER_ANY permission, you can see all rerankers or filter by any owner_id. Specifying owner_id without LIST_RERANKER_ANY permission returns PERMISSION_DENIED.

        Args:
            owner_id (str, optional): Filter rerankers by owner ID. With LIST_RERANKER_ANY permission, omitting this shows all accessible rerankers; providing it filters by that owner. With LIST_RERANKER_OWN permission, only your own rerankers are shown regardless of this parameter (PERMISSION_DENIED if set to another user).
            provider_type (ProviderType, optional): Filter rerankers by provider type. Allowed values match the ProviderType schema.
            label.* (str, optional): Filter by label value. Multiple label filters can be specified (e.g., ?label.environment=production&label.team=search)

        Returns:
            list[RerankerResponse]
        """
        op = _op_meta(self, 'list')
        _params: dict = {}
        if owner_id is not None:
            _params['owner_id'] = owner_id
        if provider_type is not None:
            _params['provider_type'] = provider_type
        params = _expand_label_filters(op=op, labels=labels, params=_params)
        resp = self._http.get(
            "/v1/rerankers",
            params=params or None,
            headers=self._headers,
        )
        raise_for_status(resp)
        wrapper = ListRerankersResponse.model_validate(resp.json())
        return getattr(wrapper, 'rerankers', [])

    def get(self, *, id: str) -> RerankerResponse:
        """Get a reranker by ID

        Retrieves the details of a specific reranker configuration by its unique identifier. Response payloads include stored credentials, matching gRPC response semantics. Requires READ_RERANKER_OWN permission for rerankers you own (or READ_RERANKER_ANY for admin users). This is a read-only operation with no side effects and is safe to retry.

        Args:
            id (str): The unique identifier of the reranker to retrieve

        Returns:
            RerankerResponse
        """
        resp = self._http.get(
            f"/v1/rerankers/{id}",
            headers=self._headers,
        )
        raise_for_status(resp)
        return RerankerResponse.model_validate(resp.json())

    def update(self, *, id: str, request: UpdateRerankerRequest | dict) -> RerankerResponse:
        """Update a reranker

        Updates an existing reranker configuration including display information, endpoint configuration, model parameters, credentials, and labels. All fields are optional - only specified fields will be updated. IMMUTABLE FIELDS: provider_type and owner_id cannot be changed after creation. SUPPORTED_MODALITIES UPDATE: If the array contains ≥1 elements, it replaces the stored set; if empty or omitted, no change occurs. Returns ALREADY_EXISTS if update would create duplicate with same {owner_id, provider_type, endpoint_url, api_path, model_identifier, credentials_fingerprint} after URL canonicalization (HTTP 409 Conflict / ALREADY_EXISTS). Requires UPDATE_RERANKER_OWN permission for rerankers you own (or UPDATE_RERANKER_ANY for admin users). This operation is idempotent.

        Args:
            id (str): The unique identifier of the reranker to update.
            request (UpdateRerankerRequest | dict): The update payload. Accepts a UpdateRerankerRequest instance or a plain dict with the same fields. Only specified fields will be modified.

        Returns:
            RerankerResponse
        """
        if isinstance(request, dict):
            request = UpdateRerankerRequest.model_validate(request)
        resp = self._http.put(
            f"/v1/rerankers/{id}",
            json=request.model_dump(by_alias=True, exclude_unset=True),
            headers=self._headers,
        )
        raise_for_status(resp)
        return RerankerResponse.model_validate(resp.json())

    def delete(self, *, id: str) -> None:
        """Delete a reranker

        Permanently deletes a reranker configuration. This operation cannot be undone and immediately removes the reranker record from the database. SIDE EFFECTS: Invalidates any cached references to this reranker; does not affect historical usage data or audit logs. Requires DELETE_RERANKER_OWN permission for rerankers you own (or DELETE_RERANKER_ANY for admin users). This operation is safe to retry - may return NOT_FOUND if already deleted.

        Args:
            id (str): The unique identifier of the reranker to delete
        """
        resp = self._http.delete(
            f"/v1/rerankers/{id}",
            headers=self._headers,
        )
        raise_for_status(resp)


class AsyncRerankersAPIBase:
    """Async Rerankers API — auto-generated structural base.

    Auto-generated structural base. Do not edit.
    Override in goodmem/api/rerankers.py to add domain-specific logic.
    """

    _create_model = RerankerCreationRequest
    _rest_metadata: dict = {'create': {'http_method': 'POST', 'path': '/v1/rerankers', 'input_shape': 'kwargs_body', 'summary': 'Create a new reranker', 'description': "Creates a new reranker configuration for ranking search results. Rerankers represent connections to different reranking API services (like TEI, OpenAI, etc.) and include all the necessary configuration to use them for result ranking. DUPLICATE DETECTION: Returns HTTP 409 Conflict (ALREADY_EXISTS) if another reranker exists with identical {ownerId, providerType, endpointUrl, apiPath, modelIdentifier, credentialsFingerprint} after URL canonicalization. Uniqueness is enforced per-owner, allowing different users to have identical configurations. Credentials are hashed (SHA-256) for uniqueness while remaining encrypted. DEFAULTS: apiPath defaults to '/v2/rerank' for Cohere and '/rerank' for other providers if omitted; supportedModalities defaults to [TEXT] if omitted. Requires CREATE_RERANKER_OWN permission (or CREATE_RERANKER_ANY for admin users). This operation is NOT idempotent - each request creates a new reranker record.", 'response': 'RerankerResponse', 'params': [{'name': 'display_name', 'type': 'str', 'source': 'body', 'required': True, 'alias': 'displayName', 'description': 'User-facing name of the reranker'}, {'name': 'description', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Description of the reranker'}, {'name': 'provider_type', 'type': 'ProviderType', 'source': 'body', 'required': True, 'alias': 'providerType', 'description': 'Type of reranking provider'}, {'name': 'endpoint_url', 'type': 'str', 'source': 'body', 'required': True, 'alias': 'endpointUrl', 'description': 'API endpoint URL'}, {'name': 'api_path', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'apiPath', 'description': 'API path for reranking request (defaults: Cohere /v2/rerank, Jina /v1/rerank, others /rerank)'}, {'name': 'model_identifier', 'type': 'str', 'source': 'body', 'required': True, 'alias': 'modelIdentifier', 'description': 'Model identifier'}, {'name': 'supported_modalities', 'type': 'list[Modality]', 'source': 'body', 'required': False, 'alias': 'supportedModalities', 'description': 'Supported content modalities (defaults to TEXT if not provided)', 'default': ['TEXT']}, {'name': 'credentials', 'type': 'EndpointAuthentication', 'source': 'body', 'required': False, 'description': 'Structured credential payload describing how to authenticate with the provider. Required for SaaS providers; optional for local deployments.'}, {'name': 'labels', 'type': 'dict', 'source': 'body', 'required': False, 'description': 'User-defined labels for categorization'}, {'name': 'version', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Version information'}, {'name': 'monitoring_endpoint', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'monitoringEndpoint', 'description': 'Monitoring endpoint URL'}, {'name': 'owner_id', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'ownerId', 'description': 'Optional owner ID. If not provided, derived from the authentication context. Requires CREATE_RERANKER_ANY permission if specified.'}, {'name': 'reranker_id', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'rerankerId', '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.'}], 'body_model': 'RerankerCreationRequest', 'body_expr': 'RerankerCreationRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'get': {'http_method': 'GET', 'path': '/v1/rerankers/{id}', 'input_shape': 'path_query', 'summary': 'Get a reranker by ID', 'description': 'Retrieves the details of a specific reranker configuration by its unique identifier. Response payloads include stored credentials, matching gRPC response semantics. Requires READ_RERANKER_OWN permission for rerankers you own (or READ_RERANKER_ANY for admin users). This is a read-only operation with no side effects and is safe to retry.', 'response': 'RerankerResponse', 'query_params': ['id'], 'params': [{'name': 'id', 'type': 'str', 'source': 'path', 'required': True, 'description': 'The unique identifier of the reranker to retrieve'}]}, 'list': {'http_method': 'GET', 'path': '/v1/rerankers', 'input_shape': 'query_only', 'summary': 'List rerankers', 'description': 'Retrieves a list of reranker configurations accessible to the caller, with optional filtering. IMPORTANT: Pagination is NOT supported - all matching results are returned. Results are ordered by created_at descending. Responses include stored credentials, matching gRPC response semantics. LABEL FILTERS: Supply dynamic query parameters in the form label.<key>=<value> (for example, label.environment=production). PERMISSION-BASED FILTERING: With LIST_RERANKER_OWN permission, only your own rerankers are shown. With LIST_RERANKER_ANY permission, you can see all rerankers or filter by any ownerId. Specifying ownerId without LIST_RERANKER_ANY permission returns PERMISSION_DENIED.', 'response': 'ListRerankersResponse', 'query_params': ['owner_id', 'provider_type', 'label.*'], 'params': [{'name': 'owner_id', 'type': 'str', 'source': 'query', 'required': False, 'alias': 'ownerId', 'description': 'Filter rerankers by owner ID. With LIST_RERANKER_ANY permission, omitting this shows all accessible rerankers; providing it filters by that owner. With LIST_RERANKER_OWN permission, only your own rerankers are shown regardless of this parameter (PERMISSION_DENIED if set to another user).'}, {'name': 'provider_type', 'type': 'ProviderType', 'source': 'query', 'required': False, 'alias': 'providerType', 'description': 'Filter rerankers by provider type. Allowed values match the ProviderType schema.'}, {'name': 'label.*', 'type': 'str', 'source': 'query', 'required': False, 'description': 'Filter by label value. Multiple label filters can be specified (e.g., ?label.environment=production&label.team=search)'}], 'supports_label_wildcard': True}, 'update': {'http_method': 'PUT', 'path': '/v1/rerankers/{id}', 'input_shape': 'typed_request', 'summary': 'Update a reranker', 'description': 'Updates an existing reranker configuration including display information, endpoint configuration, model parameters, credentials, and labels. All fields are optional - only specified fields will be updated. IMMUTABLE FIELDS: providerType and ownerId cannot be changed after creation. SUPPORTED_MODALITIES UPDATE: If the array contains ≥1 elements, it replaces the stored set; if empty or omitted, no change occurs. Returns ALREADY_EXISTS if update would create duplicate with same {ownerId, providerType, endpointUrl, apiPath, modelIdentifier, credentialsFingerprint} after URL canonicalization (HTTP 409 Conflict / ALREADY_EXISTS). Requires UPDATE_RERANKER_OWN permission for rerankers you own (or UPDATE_RERANKER_ANY for admin users). This operation is idempotent.', 'response': 'RerankerResponse', 'query_params': ['id'], 'params': [{'name': 'id', 'type': 'str', 'source': 'path', 'required': True, 'description': 'The unique identifier of the reranker to update'}, {'name': 'display_name', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'displayName', 'description': 'User-facing name of the reranker'}, {'name': 'description', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Description of the reranker'}, {'name': 'endpoint_url', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'endpointUrl', 'description': 'API endpoint URL'}, {'name': 'api_path', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'apiPath', 'description': 'API path for reranking request'}, {'name': 'model_identifier', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'modelIdentifier', 'description': 'Model identifier'}, {'name': 'supported_modalities', 'type': 'list[Modality]', 'source': 'body', 'required': False, 'alias': 'supportedModalities', 'description': 'Supported content modalities'}, {'name': 'credentials', 'type': 'EndpointAuthentication', 'source': 'body', 'required': False, 'description': 'Structured credential payload describing how to authenticate with the provider. Omit to keep existing credentials.'}, {'name': 'replace_labels', 'type': 'dict', 'source': 'body', 'required': False, 'alias': 'replaceLabels', 'description': 'Replace all existing labels with these (mutually exclusive with mergeLabels)'}, {'name': 'merge_labels', 'type': 'dict', 'source': 'body', 'required': False, 'alias': 'mergeLabels', 'description': 'Merge these labels with existing ones (mutually exclusive with replaceLabels)'}, {'name': 'version', 'type': 'str', 'source': 'body', 'required': False, 'description': 'Version information'}, {'name': 'monitoring_endpoint', 'type': 'str', 'source': 'body', 'required': False, 'alias': 'monitoringEndpoint', 'description': 'Monitoring endpoint URL'}], 'body_model': 'UpdateRerankerRequest', 'body_expr': 'UpdateRerankerRequest(**kwargs)', 'body_kind': 'json', 'body_kinds': ['application/json']}, 'delete': {'http_method': 'DELETE', 'path': '/v1/rerankers/{id}', 'input_shape': 'path_query', 'summary': 'Delete a reranker', 'description': 'Permanently deletes a reranker configuration. This operation cannot be undone and immediately removes the reranker record from the database. SIDE EFFECTS: Invalidates any cached references to this reranker; does not affect historical usage data or audit logs. Requires DELETE_RERANKER_OWN permission for rerankers you own (or DELETE_RERANKER_ANY for admin users). This operation is safe to retry - may return NOT_FOUND if already deleted.', 'response': 'None', 'query_params': ['id'], 'params': [{'name': 'id', 'type': 'str', 'source': 'path', 'required': True, 'description': 'The unique identifier of the reranker to delete'}]}}

    def __init__(self, http: httpx.AsyncClient, headers: dict[str, str]) -> None:
        self._http = http
        self._headers = headers

    async def create(self, *, display_name: str | None=None, description: str | None=None, provider_type: ProviderType | None=None, endpoint_url: str | None=None, api_path: str | None=None, model_identifier: str | None=None, supported_modalities: list | None=('TEXT',), credentials: EndpointAuthentication | None=None, labels: dict | None=None, version: str | None=None, monitoring_endpoint: str | None=None, owner_id: str | None=None, reranker_id: str | None=None) -> RerankerResponse:
        """Create a new reranker

        Creates a new reranker configuration for ranking search results. Rerankers represent connections to different reranking API services (like TEI, OpenAI, etc.) and include all the necessary configuration to use them for result ranking. DUPLICATE DETECTION: Returns HTTP 409 Conflict (ALREADY_EXISTS) if another reranker exists with identical {owner_id, provider_type, endpoint_url, api_path, model_identifier, credentials_fingerprint} after URL canonicalization. Uniqueness is enforced per-owner, allowing different users to have identical configurations. Credentials are hashed (SHA-256) for uniqueness while remaining encrypted. DEFAULTS: api_path defaults to '/v2/rerank' for Cohere and '/rerank' for other providers if omitted; supported_modalities defaults to [TEXT] if omitted. Requires CREATE_RERANKER_OWN permission (or CREATE_RERANKER_ANY for admin users). This operation is NOT idempotent - each request creates a new reranker record.

        Args:
            display_name (str): User-facing name of the reranker
            description (str, optional): Description of the reranker
            provider_type (ProviderType): Type of reranking provider
            endpoint_url (str): API endpoint URL
            api_path (str, optional): API path for reranking request (defaults: Cohere /v2/rerank, Jina /v1/rerank, others /rerank)
            model_identifier (str): Model identifier
            supported_modalities (list, optional, default=['TEXT']): Supported content modalities (defaults to TEXT if not provided)
            credentials (EndpointAuthentication, optional): Structured credential payload describing how to authenticate with the provider. Required for SaaS providers; optional for local deployments.
            labels (dict, optional): User-defined labels for categorization
            version (str, optional): Version information
            monitoring_endpoint (str, optional): Monitoring endpoint URL
            owner_id (str, optional): Optional owner ID. If not provided, derived from the authentication context. Requires CREATE_RERANKER_ANY permission if specified.
            reranker_id (str, optional): Optional client-provided UUID for idempotent creation. If not provided, server generates a new UUID. Returns ALREADY_EXISTS if ID is already in use.

        Returns:
            RerankerResponse
        """
        op = _op_meta(self, 'create')
        _params: dict = {}
        if display_name is not None:
            _params['display_name'] = display_name
        if description is not None:
            _params['description'] = description
        if provider_type is not None:
            _params['provider_type'] = provider_type
        if endpoint_url is not None:
            _params['endpoint_url'] = endpoint_url
        if api_path is not None:
            _params['api_path'] = api_path
        if model_identifier is not None:
            _params['model_identifier'] = model_identifier
        _params['supported_modalities'] = supported_modalities
        if credentials is not None:
            _params['credentials'] = credentials
        if labels is not None:
            _params['labels'] = labels
        if version is not None:
            _params['version'] = version
        if monitoring_endpoint is not None:
            _params['monitoring_endpoint'] = monitoring_endpoint
        if owner_id is not None:
            _params['owner_id'] = owner_id
        if reranker_id is not None:
            _params['reranker_id'] = reranker_id
        json_payload, data_payload, files_payload = _prepare_create_payload(
            create_model=RerankerCreationRequest, op=op, kwargs=_params,
        )
        resp = await self._http.post(
            "/v1/rerankers",
            json=json_payload,
            data=data_payload,
            files=files_payload,
            headers=self._headers,
        )
        raise_for_status(resp)
        return RerankerResponse.model_validate(resp.json())

    async def list(self, *, labels: dict[str, str] | None = None, owner_id: str | None=None, provider_type: ProviderType | None=None) -> list[RerankerResponse]:
        """List rerankers

        Retrieves a list of reranker configurations accessible to the caller, with optional filtering. IMPORTANT: Pagination is NOT supported - all matching results are returned. Results are ordered by created_at descending. Responses include stored credentials, matching gRPC response semantics. LABEL FILTERS: Supply dynamic query parameters in the form label.<key>=<value> (for example, label.environment=production). PERMISSION-BASED FILTERING: With LIST_RERANKER_OWN permission, only your own rerankers are shown. With LIST_RERANKER_ANY permission, you can see all rerankers or filter by any owner_id. Specifying owner_id without LIST_RERANKER_ANY permission returns PERMISSION_DENIED.

        Args:
            owner_id (str, optional): Filter rerankers by owner ID. With LIST_RERANKER_ANY permission, omitting this shows all accessible rerankers; providing it filters by that owner. With LIST_RERANKER_OWN permission, only your own rerankers are shown regardless of this parameter (PERMISSION_DENIED if set to another user).
            provider_type (ProviderType, optional): Filter rerankers by provider type. Allowed values match the ProviderType schema.
            label.* (str, optional): Filter by label value. Multiple label filters can be specified (e.g., ?label.environment=production&label.team=search)

        Returns:
            list[RerankerResponse]
        """
        op = _op_meta(self, 'list')
        _params: dict = {}
        if owner_id is not None:
            _params['owner_id'] = owner_id
        if provider_type is not None:
            _params['provider_type'] = provider_type
        params = _expand_label_filters(op=op, labels=labels, params=_params)
        resp = await self._http.get(
            "/v1/rerankers",
            params=params or None,
            headers=self._headers,
        )
        raise_for_status(resp)
        wrapper = ListRerankersResponse.model_validate(resp.json())
        return getattr(wrapper, 'rerankers', [])

    async def get(self, *, id: str) -> RerankerResponse:
        """Get a reranker by ID

        Retrieves the details of a specific reranker configuration by its unique identifier. Response payloads include stored credentials, matching gRPC response semantics. Requires READ_RERANKER_OWN permission for rerankers you own (or READ_RERANKER_ANY for admin users). This is a read-only operation with no side effects and is safe to retry.

        Args:
            id (str): The unique identifier of the reranker to retrieve

        Returns:
            RerankerResponse
        """
        resp = await self._http.get(
            f"/v1/rerankers/{id}",
            headers=self._headers,
        )
        raise_for_status(resp)
        return RerankerResponse.model_validate(resp.json())

    async def update(self, *, id: str, request: UpdateRerankerRequest | dict) -> RerankerResponse:
        """Update a reranker

        Updates an existing reranker configuration including display information, endpoint configuration, model parameters, credentials, and labels. All fields are optional - only specified fields will be updated. IMMUTABLE FIELDS: provider_type and owner_id cannot be changed after creation. SUPPORTED_MODALITIES UPDATE: If the array contains ≥1 elements, it replaces the stored set; if empty or omitted, no change occurs. Returns ALREADY_EXISTS if update would create duplicate with same {owner_id, provider_type, endpoint_url, api_path, model_identifier, credentials_fingerprint} after URL canonicalization (HTTP 409 Conflict / ALREADY_EXISTS). Requires UPDATE_RERANKER_OWN permission for rerankers you own (or UPDATE_RERANKER_ANY for admin users). This operation is idempotent.

        Args:
            id (str): The unique identifier of the reranker to update.
            request (UpdateRerankerRequest | dict): The update payload. Accepts a UpdateRerankerRequest instance or a plain dict with the same fields. Only specified fields will be modified.

        Returns:
            RerankerResponse
        """
        if isinstance(request, dict):
            request = UpdateRerankerRequest.model_validate(request)
        resp = await self._http.put(
            f"/v1/rerankers/{id}",
            json=request.model_dump(by_alias=True, exclude_unset=True),
            headers=self._headers,
        )
        raise_for_status(resp)
        return RerankerResponse.model_validate(resp.json())

    async def delete(self, *, id: str) -> None:
        """Delete a reranker

        Permanently deletes a reranker configuration. This operation cannot be undone and immediately removes the reranker record from the database. SIDE EFFECTS: Invalidates any cached references to this reranker; does not affect historical usage data or audit logs. Requires DELETE_RERANKER_OWN permission for rerankers you own (or DELETE_RERANKER_ANY for admin users). This operation is safe to retry - may return NOT_FOUND if already deleted.

        Args:
            id (str): The unique identifier of the reranker to delete
        """
        resp = await self._http.delete(
            f"/v1/rerankers/{id}",
            headers=self._headers,
        )
        raise_for_status(resp)

