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

// `Rank` resource client (generated, 5 operations).

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

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

    /// 获取排行榜语言
    ///
    /// `GET /ranks/repo/language-list`
    pub async fn get_language_list(
        &self,
        query: &GetLanguageListQuery,
    ) -> Result<crate::models::RankLanguageList> {
        let path = "/ranks/repo/language-list".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.rank_type {
                pairs.append_pair("rankType", v);
            }
            if let Some(ref v) = query.date {
                pairs.append_pair("date", v);
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::RankLanguageList>(Method::GET, url)
            .await
    }

    /// 获取公仓年榜
    ///
    /// `GET /ranks/repo/annual`
    pub async fn get_repo_annual_rank(
        &self,
        query: &GetRepoAnnualRankQuery,
    ) -> Result<crate::models::GetRankResult> {
        let path = "/ranks/repo/annual".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.language {
                pairs.append_pair("language", v);
            }
            if let Some(ref v) = query.flags {
                pairs.append_pair("flags", v);
            }
            if let Some(ref v) = query.year {
                pairs.append_pair("year", v);
            }
            if let Some(v) = query.top_n {
                pairs.append_pair("topN", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::GetRankResult>(Method::GET, url)
            .await
    }

    /// 获取公仓日榜
    ///
    /// `GET /ranks/repo/daily`
    pub async fn get_repo_daily_rank(
        &self,
        query: &GetRepoDailyRankQuery,
    ) -> Result<crate::models::GetRankResult> {
        let path = "/ranks/repo/daily".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.language {
                pairs.append_pair("language", v);
            }
            if let Some(ref v) = query.flags {
                pairs.append_pair("flags", v);
            }
            if let Some(ref v) = query.date {
                pairs.append_pair("date", v);
            }
            if let Some(v) = query.top_n {
                pairs.append_pair("topN", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::GetRankResult>(Method::GET, url)
            .await
    }

    /// 获取公仓月榜
    ///
    /// `GET /ranks/repo/monthly`
    pub async fn get_repo_monthly_rank(
        &self,
        query: &GetRepoMonthlyRankQuery,
    ) -> Result<crate::models::GetRankResult> {
        let path = "/ranks/repo/monthly".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.language {
                pairs.append_pair("language", v);
            }
            if let Some(ref v) = query.flags {
                pairs.append_pair("flags", v);
            }
            if let Some(ref v) = query.month {
                pairs.append_pair("month", v);
            }
            if let Some(v) = query.top_n {
                pairs.append_pair("topN", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::GetRankResult>(Method::GET, url)
            .await
    }

    /// 获取公仓周榜
    ///
    /// `GET /ranks/repo/weekly`
    pub async fn get_repo_weekly_rank(
        &self,
        query: &GetRepoWeeklyRankQuery,
    ) -> Result<crate::models::GetRankResult> {
        let path = "/ranks/repo/weekly".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.language {
                pairs.append_pair("language", v);
            }
            if let Some(ref v) = query.flags {
                pairs.append_pair("flags", v);
            }
            if let Some(ref v) = query.start {
                pairs.append_pair("start", v);
            }
            if let Some(v) = query.top_n {
                pairs.append_pair("topN", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::GetRankResult>(Method::GET, url)
            .await
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetLanguageListQuery {
    /// 排行榜类型
    #[serde(rename = "rankType", default, skip_serializing_if = "Option::is_none")]
    pub rank_type: Option<String>,
    /// 日期
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub date: Option<String>,
}

impl GetLanguageListQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `rankType` query parameter.
    pub fn rank_type(mut self, v: impl Into<String>) -> Self {
        self.rank_type = 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 GetRepoAnnualRankQuery {
    /// 语言
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
    /// 仓库类型
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<String>,
    /// 年榜年份，格式为2006，不填默认为本年
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub year: Option<String>,
    /// 排行前n名
    #[serde(rename = "topN", default, skip_serializing_if = "Option::is_none")]
    pub top_n: Option<i64>,
}

impl GetRepoAnnualRankQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `language` query parameter.
    pub fn language(mut self, v: impl Into<String>) -> Self {
        self.language = Some(v.into());
        self
    }
    /// Set `flags` query parameter.
    pub fn flags(mut self, v: impl Into<String>) -> Self {
        self.flags = Some(v.into());
        self
    }
    /// Set `year` query parameter.
    pub fn year(mut self, v: impl Into<String>) -> Self {
        self.year = Some(v.into());
        self
    }
    /// Set `topN` query parameter.
    pub fn top_n(mut self, v: impl Into<i64>) -> Self {
        self.top_n = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetRepoDailyRankQuery {
    /// 语言
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
    /// 仓库类型
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<String>,
    /// 日榜日期，默认为昨天
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub date: Option<String>,
    /// 排行前n名
    #[serde(rename = "topN", default, skip_serializing_if = "Option::is_none")]
    pub top_n: Option<i64>,
}

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

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetRepoMonthlyRankQuery {
    /// 语言
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
    /// 仓库类型
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<String>,
    /// 月榜月份，格式为200601，不填默认为本月
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub month: Option<String>,
    /// 排行前n名
    #[serde(rename = "topN", default, skip_serializing_if = "Option::is_none")]
    pub top_n: Option<i64>,
}

impl GetRepoMonthlyRankQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `language` query parameter.
    pub fn language(mut self, v: impl Into<String>) -> Self {
        self.language = Some(v.into());
        self
    }
    /// Set `flags` query parameter.
    pub fn flags(mut self, v: impl Into<String>) -> Self {
        self.flags = Some(v.into());
        self
    }
    /// Set `month` query parameter.
    pub fn month(mut self, v: impl Into<String>) -> Self {
        self.month = Some(v.into());
        self
    }
    /// Set `topN` query parameter.
    pub fn top_n(mut self, v: impl Into<i64>) -> Self {
        self.top_n = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetRepoWeeklyRankQuery {
    /// 语言
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub language: Option<String>,
    /// 仓库类型
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub flags: Option<String>,
    /// 周榜周一日期，格式为20060102，不填默认为本周
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub start: Option<String>,
    /// 排行前n名
    #[serde(rename = "topN", default, skip_serializing_if = "Option::is_none")]
    pub top_n: Option<i64>,
}

impl GetRepoWeeklyRankQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `language` query parameter.
    pub fn language(mut self, v: impl Into<String>) -> Self {
        self.language = Some(v.into());
        self
    }
    /// Set `flags` query parameter.
    pub fn flags(mut self, v: impl Into<String>) -> Self {
        self.flags = Some(v.into());
        self
    }
    /// Set `start` query parameter.
    pub fn start(mut self, v: impl Into<String>) -> Self {
        self.start = Some(v.into());
        self
    }
    /// Set `topN` query parameter.
    pub fn top_n(mut self, v: impl Into<i64>) -> Self {
        self.top_n = Some(v.into());
        self
    }
}
