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

// `RepoCodeIssue` resource client (generated, 2 operations).

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

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

    /// 获取源码扫描问题详情
    ///
    /// `GET /{slug}/-/code/issues/{record_id}`
    pub async fn get_code_issue_detail_open_api(
        &self,
        slug: String,
        record_id: i64,
    ) -> Result<crate::models::CodeIssueDetail> {
        let path = format!("/{}/-/code/issues/{}", slug, record_id);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::CodeIssueDetail>(Method::GET, url)
            .await
    }

    /// 获取源码扫描问题列表
    ///
    /// `GET /{slug}/-/code/issues`
    pub async fn list_code_issue_open_api(
        &self,
        slug: String,
        query: &ListCodeIssueOpenAPIQuery,
    ) -> Result<crate::models::CodeIssueListData> {
        let path = format!("/{}/-/code/issues", slug);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.issue_rule {
                pairs.append_pair("issue_rule", v);
            }
            if let Some(ref v) = query.risk_level {
                pairs.append_pair("risk_level", v);
            }
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::CodeIssueListData>(Method::GET, url)
            .await
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListCodeIssueOpenAPIQuery {
    /// 问题规则，用于筛选特定类型的问题。示例值：`critical-risk`, `LIC_CRITICAL`, `VUL_CRITICAL`
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub issue_rule: Option<String>,
    /// 严重程度，用于筛选特定风险等级的问题。枚举值：`info`, `warning`, `error`, `fatal`, `all`
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub risk_level: Option<String>,
    /// 分页页码。
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// 分页页大小。
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
}

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