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.removeRule
//
// 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, open_union};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::safelink::Event;
use crate::tools_ozone::safelink::PatternType;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RemoveRule<S: BosStr = DefaultStr> {
    ///Optional comment about why the rule is being removed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub comment: Option<S>,
    ///Optional DID of the user. Only respected when using admin auth.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_by: Option<Did<S>>,
    pub pattern: PatternType<S>,
    ///The URL or domain to remove the rule for
    pub url: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RemoveRuleOutput<S: BosStr = DefaultStr> {
    #[serde(flatten)]
    pub value: Event<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum RemoveRuleError {
    /// No active rule found for this URL/domain
    #[serde(rename = "RuleNotFound")]
    RuleNotFound(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for RemoveRuleError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::RuleNotFound(msg) => {
                write!(f, "RuleNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

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

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

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

pub mod remove_rule_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Url;
        type Pattern;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Url = Unset;
        type Pattern = Unset;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUrl<St> {}
    impl<St: State> State for SetUrl<St> {
        type Url = Set<members::url>;
        type Pattern = St::Pattern;
    }
    ///State transition - sets the `pattern` field to Set
    pub struct SetPattern<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPattern<St> {}
    impl<St: State> State for SetPattern<St> {
        type Url = St::Url;
        type Pattern = Set<members::pattern>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `url` field
        pub struct url(());
        ///Marker type for the `pattern` field
        pub struct pattern(());
    }
}

/// Builder for constructing an instance of this type.
pub struct RemoveRuleBuilder<S: BosStr, St: remove_rule_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<Did<S>>, Option<PatternType<S>>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

impl<S: BosStr> RemoveRule<S> {
    /// Create a new builder for this type.
    pub fn new() -> RemoveRuleBuilder<S, remove_rule_state::Empty> {
        RemoveRuleBuilder::new()
    }
}

impl<S: BosStr> RemoveRuleBuilder<S, remove_rule_state::Empty> {
    /// Create a new builder with all fields unset.
    pub fn new() -> Self {
        RemoveRuleBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: remove_rule_state::State> RemoveRuleBuilder<S, St> {
    /// Set the `comment` field (optional)
    pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `comment` field to an Option value (optional)
    pub fn maybe_comment(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<S: BosStr, St: remove_rule_state::State> RemoveRuleBuilder<S, St> {
    /// Set the `createdBy` field (optional)
    pub fn created_by(mut self, value: impl Into<Option<Did<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `createdBy` field to an Option value (optional)
    pub fn maybe_created_by(mut self, value: Option<Did<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<S: BosStr, St> RemoveRuleBuilder<S, St>
where
    St: remove_rule_state::State,
    St::Pattern: remove_rule_state::IsUnset,
{
    /// Set the `pattern` field (required)
    pub fn pattern(
        mut self,
        value: impl Into<PatternType<S>>,
    ) -> RemoveRuleBuilder<S, remove_rule_state::SetPattern<St>> {
        self._fields.2 = Option::Some(value.into());
        RemoveRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> RemoveRuleBuilder<S, St>
where
    St: remove_rule_state::State,
    St::Url: remove_rule_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<S>,
    ) -> RemoveRuleBuilder<S, remove_rule_state::SetUrl<St>> {
        self._fields.3 = Option::Some(value.into());
        RemoveRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> RemoveRuleBuilder<S, St>
where
    St: remove_rule_state::State,
    St::Url: remove_rule_state::IsSet,
    St::Pattern: remove_rule_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> RemoveRule<S> {
        RemoveRule {
            comment: self._fields.0,
            created_by: self._fields.1,
            pattern: self._fields.2.unwrap(),
            url: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> RemoveRule<S> {
        RemoveRule {
            comment: self._fields.0,
            created_by: self._fields.1,
            pattern: self._fields.2.unwrap(),
            url: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}