// @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;

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

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

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

    /// 查询仓库贡献者前 100 名的详细趋势数据。Query detailed trend data for top 100 contributors of the repository.
    ///
    /// `GET /{slug}/-/contributor/trend`
    pub async fn get_repo_contributor_trend(
        &self,
        slug: String,
        query: &GetRepoContributorTrendQuery,
    ) -> Result<crate::models::RepoContribTrend> {
        let path = format!("/{}/-/contributor/trend", slug);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(v) = query.limit {
                pairs.append_pair("limit", &v.to_string());
            }
            if let Some(v) = query.exclude_external_users {
                pairs.append_pair("exclude_external_users", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::RepoContribTrend>(Method::GET, url)
            .await
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetRepoContributorTrendQuery {
    /// 查询结果数量限制，当limit小于0时，默认为15。格式：\[0,100\]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// 是否排除外部用户。示例值：`true`,`false`
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub exclude_external_users: Option<bool>,
}

impl GetRepoContributorTrendQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `limit` query parameter.
    pub fn limit(mut self, v: impl Into<i64>) -> Self {
        self.limit = Some(v.into());
        self
    }
    /// Set `exclude_external_users` query parameter.
    pub fn exclude_external_users(mut self, v: impl Into<bool>) -> Self {
        self.exclude_external_users = Some(v.into());
        self
    }
}
