uarp-sdk 0.5.7

Async Rust client for the UARP (Snaga) Universal Agent Runtime Platform API
Documentation
// Code generated by @uarp/codegen from spec/openapi.json. DO NOT EDIT.
//!
//! Content reports — abuse/moderation reporting for authenticated users and anonymous
//! public-chat visitors, plus the operator inbox

#![allow(unused_imports, clippy::too_many_arguments)]

use reqwest::Method;
use serde::{Deserialize, Serialize};
use futures_core::Stream;

use crate::client::{Client, Request, NO_BODY, NO_QUERY};
use crate::error::Result;
use crate::generated::models;
use crate::multipart::{field_text, FilePart};
use crate::pagination::CursorGuard;
use crate::util::encode_path;

/// Query and header parameters for `listAllContentReports`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ListAllContentReportsParams {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
}

/// Query and header parameters for `listContentReports`.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct ListContentReportsParams {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
}

/// Content reports — abuse/moderation reporting for authenticated users and anonymous
/// public-chat visitors, plus the operator inbox
#[derive(Debug, Clone)]
pub struct ReportsApi {
    pub(crate) client: Client,
}

impl Client {
    /// Content reports — abuse/moderation reporting for authenticated users and anonymous
    /// public-chat visitors, plus the operator inbox
    pub fn reports(&self) -> ReportsApi {
        ReportsApi { client: self.clone() }
    }
}

impl ReportsApi {
    /// File a content report
    ///
    /// Report a message, session or agent. Available to any authenticated principal — deliberately
    /// not role- or scope-gated, since reporting abuse must never be blocked by RBAC. Rate limited
    /// to 10/minute per caller. `self_harm` is still accepted with 202 but raises the operator
    /// notification to critical priority.
    ///
    /// `POST /api/v1/reports`
    pub async fn create_content_report(&self, body: &models::ContentReportInput) -> Result<models::ContentReportAccepted> {
        self.client
            .request_json(Request {
                method: Method::POST,
                path: "/api/v1/reports".to_string(),
                query: NO_QUERY,
                body: Some(body),
                headers: Vec::new(),
                idempotent: true,
            })
            .await
    }

    /// List content reports platform-wide (super-admin)
    ///
    /// Every report across every tenant, newest first. A tenant whose agent is the problem must not
    /// be the only party holding the evidence.
    ///
    /// `GET /api/v1/admin/reports`
    ///
    /// Required scopes: `admin`.
    pub async fn list_all_content_reports(&self, params: &ListAllContentReportsParams) -> Result<models::ListAllContentReportsResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/admin/reports".to_string(),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Stream every item returned by `listAllContentReports`, following the `cursor` cursor until
    /// the server reports no further pages.
    pub fn list_all_content_reports_all<'a>(&'a self, params: &'a ListAllContentReportsParams) -> impl Stream<Item = Result<models::ContentReport>> + 'a {
        async_stream::try_stream! {
            let mut guard = CursorGuard::new();
            let mut cursor = params.cursor.clone();
            loop {
                let mut page_params = params.clone();
                page_params.cursor = cursor.clone();
                let page = self.list_all_content_reports(&page_params).await?;
                let items = page.items;
                let was_empty = items.is_empty();
                for item in items {
                    yield item;
                }
                match guard.advance(page.cursor, Some(page.has_more), was_empty) {
                    Some(next) => cursor = Some(next),
                    None => break,
                }
            }
        }
    }

    /// List content reports for this tenant (admin+)
    ///
    /// Moderation queue for the tenant that owns the reported content, newest first. Requires the
    /// admin role — reports carry reporter free text and there is no moderation duty below admin.
    ///
    /// `GET /api/v1/reports`
    pub async fn list_content_reports(&self, params: &ListContentReportsParams) -> Result<models::ListContentReportsResponse> {
        self.client
            .request_json(Request {
                method: Method::GET,
                path: "/api/v1/reports".to_string(),
                query: Some(params),
                body: NO_BODY,
                headers: Vec::new(),
                idempotent: false,
            })
            .await
    }

    /// Stream every item returned by `listContentReports`, following the `cursor` cursor until the
    /// server reports no further pages.
    pub fn list_content_reports_all<'a>(&'a self, params: &'a ListContentReportsParams) -> impl Stream<Item = Result<models::ContentReport>> + 'a {
        async_stream::try_stream! {
            let mut guard = CursorGuard::new();
            let mut cursor = params.cursor.clone();
            loop {
                let mut page_params = params.clone();
                page_params.cursor = cursor.clone();
                let page = self.list_content_reports(&page_params).await?;
                let items = page.items;
                let was_empty = items.is_empty();
                for item in items {
                    yield item;
                }
                match guard.advance(page.cursor, Some(page.has_more), was_empty) {
                    Some(next) => cursor = Some(next),
                    None => break,
                }
            }
        }
    }
}