// 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::*;
use serde::Serialize;

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

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

impl GenerateParams {
    /// Construct a new `GenerateParams` 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>, I: IntoIterator<Item = D>>(documents: I) -> Self {
        Self {
            body: GenerateSchemaRequest {
                documents: documents.into_iter().map(Into::into).collect(),
                model: Default::default(),
                reasoning_effort: Default::default(),
                instructions: Default::default(),
                image_resolution_dpi: Default::default(),
                stream: Default::default(),
            },
        }
    }
}

impl<'a> SchemasApi<'a> {
    /// Generate Schema From Examples
    ///
    /// Generates a JSON Schema from scratch by inferring structure from the content of the provided example documents.
    pub async fn generate(&self, params: GenerateParams) -> Result<PartialSchema, Error> {
        self.generate_with_options(params, None).await
    }

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