// @generated DO NOT EDIT.
//
// Generated from the CNB OpenAPI specification by `cnb-codegen`.
// Run `cargo run -p cnb-codegen --manifest-path codegen/Cargo.toml \
//      -- --spec codegen/spec/swagger.json --out src` to refresh.

#![allow(clippy::all)]
#![allow(missing_docs)]
#![allow(unused_imports)]
#![allow(unused_mut)]

use reqwest::Method;
use serde::Serialize;

use crate::error::{ApiError, Result};
use crate::http::HttpInner;
use crate::models;

// `AI` resource client (generated, 1 operations).

/// Resource client.
#[derive(Debug, Clone)]
pub struct AiClient {
    inner: HttpInner,
}

impl AiClient {
    /// Construct a new resource client. Normally obtained
    /// via [`crate::ApiClient`] rather than directly.
    pub fn new(inner: HttpInner) -> Self {
        Self { inner }
    }

    /// AI 对话。调用者需有代码写权限（CNB_TOKEN 仅需读权限，部署令牌不检查读写权限）。AI chat completions. Requires caller to have repo write permission.
    ///
    /// `POST /{repo}/-/ai/chat/completions`
    pub async fn ai_chat_completions(
        &self,
        repo: String,
        body: &crate::models::AiChatCompletionsReq,
    ) -> Result<crate::models::AiChatCompletionsResult> {
        let path = format!("/{}/-/ai/chat/completions", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<crate::models::AiChatCompletionsResult, _>(Method::POST, url, body)
            .await
    }
}
