// Code generated by oagen. DO NOT EDIT.

use crate::client::Retab;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct TablesApi<'a> {
    pub(crate) client: &'a Retab,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: BodyCreateTableV1TablesPost,
}

impl CreateParams {
    /// Construct a new `CreateParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: BodyCreateTableV1TablesPost) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct ReplaceParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: BodyReplaceTableV1TablesTableIdPut,
}

impl ReplaceParams {
    /// Construct a new `ReplaceParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: BodyReplaceTableV1TablesTableIdPut) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct UpdateTableParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: UpdateWorkflowTableRequest,
}

impl UpdateTableParams {
    /// Construct a new `UpdateTableParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: UpdateWorkflowTableRequest) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ProfileParams {
    /// Defaults to `[]`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub select: Option<Vec<String>>,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct QueryParams {
    /// Request body sent with this call.
    #[serde(skip)]
    pub body: Option<QueryWorkflowTableRequest>,
}

#[derive(Debug, Clone, Serialize)]
pub struct ValidateParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: WorkflowTableValidationRequest,
}

impl ValidateParams {
    /// Construct a new `ValidateParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: WorkflowTableValidationRequest) -> Self {
        Self { body }
    }
}

impl<'a> TablesApi<'a> {
    /// List Tables
    pub async fn list(&self) -> Result<WorkflowTableListResponse, Error> {
        self.list_with_options(None).await
    }

    /// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_with_options(
        &self,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableListResponse, Error> {
        let path = "/v1/tables".to_string();
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Create Table
    pub async fn create(&self, params: CreateParams) -> Result<WorkflowTableListResponse, Error> {
        self.create_with_options(params, None).await
    }

    /// Variant of [`Self::create`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_with_options(
        &self,
        params: CreateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableListResponse, Error> {
        let path = "/v1/tables".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Table
    pub async fn get(&self, table_id: &str) -> Result<WorkflowTableResponse, Error> {
        self.get_with_options(table_id, None).await
    }

    /// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_with_options(
        &self,
        table_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Replace Table
    pub async fn replace(
        &self,
        table_id: &str,
        params: ReplaceParams,
    ) -> Result<WorkflowTableListResponse, Error> {
        self.replace_with_options(table_id, params, None).await
    }

    /// Variant of [`Self::replace`] that accepts per-request [`crate::RequestOptions`].
    pub async fn replace_with_options(
        &self,
        table_id: &str,
        params: ReplaceParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableListResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}");
        let method = http::Method::PUT;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Update Table
    pub async fn update_table(
        &self,
        table_id: &str,
        params: UpdateTableParams,
    ) -> Result<WorkflowTableListResponse, Error> {
        self.update_table_with_options(table_id, params, None).await
    }

    /// Variant of [`Self::update_table`] that accepts per-request [`crate::RequestOptions`].
    pub async fn update_table_with_options(
        &self,
        table_id: &str,
        params: UpdateTableParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableListResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}");
        let method = http::Method::PATCH;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Delete Table
    pub async fn delete(&self, table_id: &str) -> Result<WorkflowTableListResponse, Error> {
        self.delete_with_options(table_id, None).await
    }

    /// Variant of [`Self::delete`] that accepts per-request [`crate::RequestOptions`].
    pub async fn delete_with_options(
        &self,
        table_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableListResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}");
        let method = http::Method::DELETE;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Download Table Csv
    pub async fn download(&self, table_id: &str) -> Result<(), Error> {
        self.download_with_options(table_id, None).await
    }

    /// Variant of [`Self::download`] that accepts per-request [`crate::RequestOptions`].
    pub async fn download_with_options(
        &self,
        table_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<(), Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}/download");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts_empty(method, &path, &(), options)
            .await
    }

    /// Profile Table
    pub async fn profile(
        &self,
        table_id: &str,
        params: ProfileParams,
    ) -> Result<WorkflowTableProfileResponse, Error> {
        self.profile_with_options(table_id, params, None).await
    }

    /// Variant of [`Self::profile`] that accepts per-request [`crate::RequestOptions`].
    pub async fn profile_with_options(
        &self,
        table_id: &str,
        params: ProfileParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableProfileResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}/profile");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// Query Table
    pub async fn query(
        &self,
        table_id: &str,
        params: QueryParams,
    ) -> Result<WorkflowTableRowsResponse, Error> {
        self.query_with_options(table_id, params, None).await
    }

    /// Variant of [`Self::query`] that accepts per-request [`crate::RequestOptions`].
    pub async fn query_with_options(
        &self,
        table_id: &str,
        params: QueryParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableRowsResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}/query");
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, params.body.as_ref(), options)
            .await
    }

    /// Get Table Schema
    pub async fn schema(&self, table_id: &str) -> Result<WorkflowTableSchemaResponse, Error> {
        self.schema_with_options(table_id, None).await
    }

    /// Variant of [`Self::schema`] that accepts per-request [`crate::RequestOptions`].
    pub async fn schema_with_options(
        &self,
        table_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableSchemaResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}/schema");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }

    /// Validate Table
    pub async fn validate(
        &self,
        table_id: &str,
        params: ValidateParams,
    ) -> Result<WorkflowTableValidationResponse, Error> {
        self.validate_with_options(table_id, params, None).await
    }

    /// Variant of [`Self::validate`] that accepts per-request [`crate::RequestOptions`].
    pub async fn validate_with_options(
        &self,
        table_id: &str,
        params: ValidateParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WorkflowTableValidationResponse, Error> {
        let table_id = crate::client::path_segment(table_id);
        let path = format!("/v1/tables/{table_id}/validate");
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }
}
