typesense-rs 27.0.1

An open source search engine for building delightful search experiences.
Documentation
// Typesense API
//
// An open source search engine for building delightful search experiences.
//
// The version of the OpenAPI document: 27.0
//
// Generated by: https://openapi-generator.tech

use std::sync::Arc;

use async_trait::async_trait;
use reqwest;
use serde::{Deserialize, Serialize};

use super::{configuration, Error};
use crate::apis::ResponseContent;
use crate::models;

#[async_trait]
pub trait ConversationsApi: Send + Sync {
	async fn create_conversation_model(
		&self,
		params: CreateConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<CreateConversationModelError>>;
	async fn delete_conversation_model(
		&self,
		params: DeleteConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<DeleteConversationModelError>>;
	async fn retrieve_all_conversation_models(
		&self,
	) -> Result<Vec<models::ConversationModelSchema>, Error<RetrieveAllConversationModelsError>>;
	async fn retrieve_conversation_model(
		&self,
		params: RetrieveConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<RetrieveConversationModelError>>;
	async fn update_conversation_model(
		&self,
		params: UpdateConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<UpdateConversationModelError>>;
}

pub struct ConversationsApiClient {
	configuration: Arc<configuration::Configuration>,
}

impl ConversationsApiClient {
	pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
		Self { configuration }
	}
}

/// struct for passing parameters to the method [`create_conversation_model`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct CreateConversationModelParams {
	pub conversation_model_create_schema: models::ConversationModelCreateSchema,
}

/// struct for passing parameters to the method [`delete_conversation_model`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct DeleteConversationModelParams {
	/// The id of the conversation model to delete
	pub model_id: String,
}

/// struct for passing parameters to the method [`retrieve_conversation_model`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct RetrieveConversationModelParams {
	/// The id of the conversation model to retrieve
	pub model_id: String,
}

/// struct for passing parameters to the method [`update_conversation_model`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct UpdateConversationModelParams {
	/// The id of the conversation model to update
	pub model_id: String,
	pub conversation_model_update_schema: models::ConversationModelUpdateSchema,
}

#[async_trait]
impl ConversationsApi for ConversationsApiClient {
	/// Create a Conversation Model
	async fn create_conversation_model(
		&self,
		params: CreateConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<CreateConversationModelError>> {
		let CreateConversationModelParams {
			conversation_model_create_schema,
		} = params;

		let local_var_configuration = &self.configuration;

		let local_var_client = &local_var_configuration.client;

		let local_var_uri_str = format!("{}/conversations/models", local_var_configuration.base_path);
		let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
		}
		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
			let local_var_key = local_var_apikey.key.clone();
			let local_var_value = match local_var_apikey.prefix {
				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
				None => local_var_key,
			};
			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
		};
		local_var_req_builder = local_var_req_builder.json(&conversation_model_create_schema);

		let local_var_req = local_var_req_builder.build()?;
		let local_var_resp = local_var_client.execute(local_var_req).await?;

		let local_var_status = local_var_resp.status();
		let local_var_content = local_var_resp.text().await?;

		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
			serde_json::from_str(&local_var_content).map_err(Error::from)
		} else {
			let local_var_entity: Option<CreateConversationModelError> = serde_json::from_str(&local_var_content).ok();
			let local_var_error = ResponseContent {
				status: local_var_status,
				content: local_var_content,
				entity: local_var_entity,
			};
			Err(Error::ResponseError(local_var_error))
		}
	}

	/// Delete a conversation model
	async fn delete_conversation_model(
		&self,
		params: DeleteConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<DeleteConversationModelError>> {
		let DeleteConversationModelParams { model_id } = params;

		let local_var_configuration = &self.configuration;

		let local_var_client = &local_var_configuration.client;

		let local_var_uri_str = format!(
			"{}/conversations/models/{modelId}",
			local_var_configuration.base_path,
			modelId = crate::apis::urlencode(model_id)
		);
		let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());

		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
		}
		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
			let local_var_key = local_var_apikey.key.clone();
			let local_var_value = match local_var_apikey.prefix {
				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
				None => local_var_key,
			};
			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
		};

		let local_var_req = local_var_req_builder.build()?;
		let local_var_resp = local_var_client.execute(local_var_req).await?;

		let local_var_status = local_var_resp.status();
		let local_var_content = local_var_resp.text().await?;

		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
			serde_json::from_str(&local_var_content).map_err(Error::from)
		} else {
			let local_var_entity: Option<DeleteConversationModelError> = serde_json::from_str(&local_var_content).ok();
			let local_var_error = ResponseContent {
				status: local_var_status,
				content: local_var_content,
				entity: local_var_entity,
			};
			Err(Error::ResponseError(local_var_error))
		}
	}

	/// Retrieve all conversation models
	async fn retrieve_all_conversation_models(
		&self,
	) -> Result<Vec<models::ConversationModelSchema>, Error<RetrieveAllConversationModelsError>> {
		let local_var_configuration = &self.configuration;

		let local_var_client = &local_var_configuration.client;

		let local_var_uri_str = format!("{}/conversations/models", local_var_configuration.base_path);
		let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
		}
		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
			let local_var_key = local_var_apikey.key.clone();
			let local_var_value = match local_var_apikey.prefix {
				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
				None => local_var_key,
			};
			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
		};

		let local_var_req = local_var_req_builder.build()?;
		let local_var_resp = local_var_client.execute(local_var_req).await?;

		let local_var_status = local_var_resp.status();
		let local_var_content = local_var_resp.text().await?;

		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
			serde_json::from_str(&local_var_content).map_err(Error::from)
		} else {
			let local_var_entity: Option<RetrieveAllConversationModelsError> = serde_json::from_str(&local_var_content).ok();
			let local_var_error = ResponseContent {
				status: local_var_status,
				content: local_var_content,
				entity: local_var_entity,
			};
			Err(Error::ResponseError(local_var_error))
		}
	}

	/// Retrieve a conversation model
	async fn retrieve_conversation_model(
		&self,
		params: RetrieveConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<RetrieveConversationModelError>> {
		let RetrieveConversationModelParams { model_id } = params;

		let local_var_configuration = &self.configuration;

		let local_var_client = &local_var_configuration.client;

		let local_var_uri_str = format!(
			"{}/conversations/models/{modelId}",
			local_var_configuration.base_path,
			modelId = crate::apis::urlencode(model_id)
		);
		let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
		}
		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
			let local_var_key = local_var_apikey.key.clone();
			let local_var_value = match local_var_apikey.prefix {
				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
				None => local_var_key,
			};
			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
		};

		let local_var_req = local_var_req_builder.build()?;
		let local_var_resp = local_var_client.execute(local_var_req).await?;

		let local_var_status = local_var_resp.status();
		let local_var_content = local_var_resp.text().await?;

		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
			serde_json::from_str(&local_var_content).map_err(Error::from)
		} else {
			let local_var_entity: Option<RetrieveConversationModelError> = serde_json::from_str(&local_var_content).ok();
			let local_var_error = ResponseContent {
				status: local_var_status,
				content: local_var_content,
				entity: local_var_entity,
			};
			Err(Error::ResponseError(local_var_error))
		}
	}

	/// Update a conversation model
	async fn update_conversation_model(
		&self,
		params: UpdateConversationModelParams,
	) -> Result<models::ConversationModelSchema, Error<UpdateConversationModelError>> {
		let UpdateConversationModelParams {
			model_id,
			conversation_model_update_schema,
		} = params;

		let local_var_configuration = &self.configuration;

		let local_var_client = &local_var_configuration.client;

		let local_var_uri_str = format!(
			"{}/conversations/models/{modelId}",
			local_var_configuration.base_path,
			modelId = crate::apis::urlencode(model_id)
		);
		let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());

		if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
			local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
		}
		if let Some(ref local_var_apikey) = local_var_configuration.api_key {
			let local_var_key = local_var_apikey.key.clone();
			let local_var_value = match local_var_apikey.prefix {
				Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
				None => local_var_key,
			};
			local_var_req_builder = local_var_req_builder.header("X-TYPESENSE-API-KEY", local_var_value);
		};
		local_var_req_builder = local_var_req_builder.json(&conversation_model_update_schema);

		let local_var_req = local_var_req_builder.build()?;
		let local_var_resp = local_var_client.execute(local_var_req).await?;

		let local_var_status = local_var_resp.status();
		let local_var_content = local_var_resp.text().await?;

		if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
			serde_json::from_str(&local_var_content).map_err(Error::from)
		} else {
			let local_var_entity: Option<UpdateConversationModelError> = serde_json::from_str(&local_var_content).ok();
			let local_var_error = ResponseContent {
				status: local_var_status,
				content: local_var_content,
				entity: local_var_entity,
			};
			Err(Error::ResponseError(local_var_error))
		}
	}
}

/// struct for typed errors of method [`create_conversation_model`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateConversationModelError {
	Status400(models::ApiResponse),
	UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`delete_conversation_model`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteConversationModelError {
	UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`retrieve_all_conversation_models`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RetrieveAllConversationModelsError {
	UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`retrieve_conversation_model`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RetrieveConversationModelError {
	UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`update_conversation_model`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateConversationModelError {
	UnknownValue(serde_json::Value),
}