// 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 ParsesApi<'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<ParsesOrder>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub filename: Option<String>,
    #[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(ParsesOrder::Desc),
            filename: 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: ParseRequest,
}

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) -> Self {
        Self {
            body: ParseRequest {
                document: ClassificationRequestDocumentOneOf::MimeData(Box::new(document.into())),
                model: Default::default(),
                table_parsing_format: Default::default(),
                image_resolution_dpi: Default::default(),
                instructions: 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> ParsesApi<'a> {
    /// List Parses
    ///
    /// List parses.
    ///
    /// Returns a paginated list of parses for the authenticated environment, newest first by
    /// default. Filter by `filename` prefix (case-insensitive) and by a `created_at` window
    /// using `from_date`/`to_date` (`YYYY-MM-DD`). Page through results with `before`/`after`,
    /// `limit`, and `order`.
    pub async fn list(&self, params: ListParams) -> Result<ParseList, 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<ParseList, Error> {
        let path = "/v1/parses".to_string();
        let method = http::Method::GET;
        self.client
            .request_page(method, &path, &params, "after", options)
            .await
    }

    /// Create Parse
    ///
    /// Create a parse.
    ///
    /// Extracts the full text of a `document` into per-page and concatenated text using
    /// the chosen `model`. Tables are rendered in the requested `table_parsing_format`, and
    /// optional `instructions` steer the parse. Returns the stored `Parse` with its `output`
    /// and `usage`, and responds with `201`.
    pub async fn create(&self, params: CreateParams) -> Result<Parse, 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<Parse, Error> {
        let path = "/v1/parses".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }

    /// Get Parse
    ///
    /// Retrieve a parse.
    ///
    /// Fetches a single parse by its `parse_id` within the authenticated environment and
    /// returns the full `Parse` including its `output`. Responds with `404` if no parse with
    /// that id exists.
    pub async fn get(&self, parse_id: &str, params: GetParams) -> Result<Parse, Error> {
        self.get_with_options(parse_id, params, None).await
    }

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

    /// Delete Parse
    ///
    /// Delete a parse.
    ///
    /// Permanently deletes the parse identified by `parse_id` in the authenticated
    /// environment. Returns `204` with no body on success, or `404` if the parse does not
    /// exist.
    pub async fn delete(&self, parse_id: &str) -> Result<(), Error> {
        self.delete_with_options(parse_id, None).await
    }

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

    /// Cancel Parse
    pub async fn cancel(&self, parse_id: &str) -> Result<Parse, Error> {
        self.cancel_with_options(parse_id, None).await
    }

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