jacquard-api 0.12.0-beta.1

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.safelink.queryRules
//
// 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;

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct QueryRules<S: BosStr = DefaultStr> {
    ///Filter by action types
    #[serde(skip_serializing_if = "Option::is_none")]
    pub actions: Option<Vec<S>>,
    ///Filter by rule creator
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_by: Option<Did<S>>,
    ///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_rules_limit")]
    pub limit: Option<i64>,
    ///Filter by pattern type
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pattern_type: Option<S>,
    ///Filter by reason type
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason: Option<S>,
    ///Sort direction
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sort_direction: Option<QueryRulesSortDirection<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 QueryRulesSortDirection<S: BosStr = DefaultStr> {
    Asc,
    Desc,
    Other(S),
}

impl<S: BosStr> QueryRulesSortDirection<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 QueryRulesSortDirection<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

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

impl<S: BosStr> Serialize for QueryRulesSortDirection<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 QueryRulesSortDirection<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 QueryRulesSortDirection<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct QueryRulesOutput<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 rules: Vec<UrlRule<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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