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

// `Activities` resource client (generated, 3 operations).

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

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

    /// 获取个人动态活跃详情汇总。Get user activities by date.
    ///
    /// `GET /users/{username}/activities`
    pub async fn get_user_activities_by_date(
        &self,
        username: String,
        query: &GetUserActivitiesByDateQuery,
    ) -> Result<crate::models::ActivityDate> {
        let path = format!("/users/{}/activities", username);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.date {
                pairs.append_pair("date", v);
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::ActivityDate>(Method::GET, url)
            .await
    }

    /// 个人仓库动态详情列表。List of personal repository activity details.
    ///
    /// `GET /users/{username}/repo-activities/{activityType}`
    pub async fn get_user_repo_activity_details(
        &self,
        username: String,
        activity_type: String,
        query: &GetUserRepoActivityDetailsQuery,
    ) -> Result<Vec<serde_json::Value>> {
        let path = format!("/users/{}/repo-activities/{}", username, activity_type);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.slug {
                pairs.append_pair("slug", v);
            }
            if let Some(ref v) = query.date {
                pairs.append_pair("date", v);
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<serde_json::Value>>(Method::GET, url)
            .await
    }

    /// 获取仓库 top 活跃用户。List the top active users
    ///
    /// `GET /{repo}/-/top-activity-users`
    pub async fn top_contributors(
        &self,
        repo: String,
        query: &TopContributorsQuery,
    ) -> Result<Vec<crate::models::UsersResult>> {
        let path = format!("/{}/-/top-activity-users", repo);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(v) = query.top {
                pairs.append_pair("top", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<crate::models::UsersResult>>(Method::GET, url)
            .await
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetUserActivitiesByDateQuery {
    /// 查询日期，格式 yyyyMM，或者 yyyyMMdd
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub date: Option<String>,
}

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

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetUserRepoActivityDetailsQuery {
    /// 仓库路径
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub slug: Option<String>,
    /// 查询日期，格式 yyyyMM，或者 yyyyMMdd
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub date: Option<String>,
}

impl GetUserRepoActivityDetailsQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `slug` query parameter.
    pub fn slug(mut self, v: impl Into<String>) -> Self {
        self.slug = Some(v.into());
        self
    }
    /// Set `date` query parameter.
    pub fn date(mut self, v: impl Into<String>) -> Self {
        self.date = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct TopContributorsQuery {
    /// 返回的用户个数
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub top: Option<i64>,
}

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