// 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 ClassificationsApi<'a> {
    pub(crate) client: &'a Retab,
}

#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Defaults to `10`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Defaults to `desc`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<ClassificationsOrder>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filename: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<ClassificationsStatus>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub from_date: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub to_date: Option<String>,
}

impl Default for ListParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            before: Default::default(),
            after: Default::default(),
            limit: Some(10),
            order: Some(ClassificationsOrder::Desc),
            filename: Default::default(),
            status: Default::default(),
            from_date: Default::default(),
            to_date: Default::default(),
        }
    }
}

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

impl CreateParams {
    /// Construct a new `CreateParams` with the required fields set.
    ///
    /// Accepts ergonomic input for MimeData-typed fields via
    /// [`Into<MimeData>`](crate::MimeData) — pass a `PathBuf`,
    /// `Vec<u8>`, `&str` URL, or pre-built `MimeData`.
    #[allow(deprecated)]
    pub fn new<D: Into<crate::MimeData>>(document: D, categories: Vec<Category>) -> Self {
        Self {
            body: ClassificationRequest {
                document: document.into(),
                categories,
                model: Default::default(),
                first_n_pages: Default::default(),
                instructions: Default::default(),
                n_consensus: Default::default(),
                bust_cache: Default::default(),
                background: Default::default(),
            },
        }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct GetParams {
    /// When false, returns a cheap status-only projection (no output), served from cache for in-flight background runs.
    ///
    /// Defaults to `true`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_output: Option<bool>,
}

impl Default for GetParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            include_output: Some(true),
        }
    }
}

impl<'a> ClassificationsApi<'a> {
    /// List Classifications
    ///
    /// List classifications.
    ///
    /// Returns a paginated list of classifications, most recent first. Filter by
    /// `filename` or a `from_date`/`to_date` range, and page with `before`/`after`.
    pub async fn list(&self, params: ListParams) -> Result<ClassificationList, Error> {
        self.list_with_options(params, None).await
    }

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

    /// Create Classification
    ///
    /// Classify a document.
    ///
    /// Runs a classification on the supplied `document` against the provided
    /// `categories`. Tune the run with `model`, `instructions`, `first_n_pages`
    /// (limit to the first pages), and `n_consensus` (number of votes to combine).
    /// Returns the created classification with the chosen category and reasoning;
    /// responds with `201`.
    pub async fn create(&self, params: CreateParams) -> Result<Classification, 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<Classification, Error> {
        let path = "/v1/classifications".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Classification
    ///
    /// Retrieve a classification.
    ///
    /// Fetches a single classification by its `classification_id`. Returns the
    /// classification with its file reference, categories, and result; responds
    /// with `404` if no classification with that id exists.
    pub async fn get(
        &self,
        classification_id: &str,
        params: GetParams,
    ) -> Result<Classification, Error> {
        self.get_with_options(classification_id, params, None).await
    }

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

    /// Delete Classification
    ///
    /// Delete a classification.
    ///
    /// Permanently deletes the classification identified by `classification_id`.
    /// Returns `204` on success, or `404` if no classification with that id exists.
    pub async fn delete(&self, classification_id: &str) -> Result<(), Error> {
        self.delete_with_options(classification_id, None).await
    }

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

    /// Cancel Classification
    pub async fn create_classification_cancel(
        &self,
        classification_id: &str,
    ) -> Result<Classification, Error> {
        self.create_classification_cancel_with_options(classification_id, None)
            .await
    }

    /// Variant of [`Self::create_classification_cancel`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_classification_cancel_with_options(
        &self,
        classification_id: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<Classification, Error> {
        let classification_id = crate::client::path_segment(classification_id);
        let path = format!("/v1/classifications/{classification_id}/cancel");
        let method = http::Method::POST;
        self.client
            .request_with_query_opts(method, &path, &(), options)
            .await
    }
}
