jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.safelink.queryEvents
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

use crate::tools_ozone::safelink::Event;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::IntoStatic;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct QueryEvents<S: BosStr = DefaultStr> {
    ///Cursor for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    ///Maximum number of results to return  Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_query_events_limit")]
    pub limit: Option<i64>,
    ///Filter by pattern type
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pattern_type: Option<S>,
    ///Sort direction
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort_direction: Option<QueryEventsSortDirection<S>>,
    ///Filter by specific URLs or domains
    #[serde(skip_serializing_if = "Option::is_none")]
    pub urls: Option<Vec<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Sort direction

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum QueryEventsSortDirection<S: BosStr = DefaultStr> {
    Asc,
    Desc,
    Other(S),
}

impl<S: BosStr> QueryEventsSortDirection<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Asc => "asc",
            Self::Desc => "desc",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "asc" => Self::Asc,
            "desc" => Self::Desc,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for QueryEventsSortDirection<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for QueryEventsSortDirection<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for QueryEventsSortDirection<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for QueryEventsSortDirection<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for QueryEventsSortDirection<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for QueryEventsSortDirection<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = QueryEventsSortDirection<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            QueryEventsSortDirection::Asc => QueryEventsSortDirection::Asc,
            QueryEventsSortDirection::Desc => QueryEventsSortDirection::Desc,
            QueryEventsSortDirection::Other(v) => QueryEventsSortDirection::Other(v.into_static()),
        }
    }
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct QueryEventsOutput<S: BosStr = DefaultStr> {
    ///Next cursor for pagination. Only present if there are more results.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub events: Vec<Event<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Response type for tools.ozone.safelink.queryEvents
pub struct QueryEventsResponse;
impl jacquard_common::xrpc::XrpcResp for QueryEventsResponse {
    const NSID: &'static str = "tools.ozone.safelink.queryEvents";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = QueryEventsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for QueryEvents<S> {
    const NSID: &'static str = "tools.ozone.safelink.queryEvents";
    const METHOD: jacquard_common::xrpc::XrpcMethod =
        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
    type Response = QueryEventsResponse;
}

/// Endpoint type for tools.ozone.safelink.queryEvents
pub struct QueryEventsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for QueryEventsRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.safelink.queryEvents";
    const METHOD: jacquard_common::xrpc::XrpcMethod =
        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
    type Request<S: BosStr> = QueryEvents<S>;
    type Response = QueryEventsResponse;
}

fn _default_query_events_limit() -> Option<i64> {
    Some(50i64)
}