#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::safelink::ActionType;
use crate::tools_ozone::safelink::Event;
use crate::tools_ozone::safelink::PatternType;
use crate::tools_ozone::safelink::ReasonType;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AddRule<'a> {
#[serde(borrow)]
pub action: ActionType<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub comment: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub created_by: Option<Did<'a>>,
#[serde(borrow)]
pub pattern: PatternType<'a>,
#[serde(borrow)]
pub reason: ReasonType<'a>,
#[serde(borrow)]
pub url: CowStr<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AddRuleOutput<'a> {
#[serde(flatten)]
#[serde(borrow)]
pub value: Event<'a>,
}
#[open_union]
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic,
IntoStatic
)]
#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum AddRuleError<'a> {
#[serde(rename = "InvalidUrl")]
InvalidUrl(Option<CowStr<'a>>),
#[serde(rename = "RuleAlreadyExists")]
RuleAlreadyExists(Option<CowStr<'a>>),
}
impl core::fmt::Display for AddRuleError<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidUrl(msg) => {
write!(f, "InvalidUrl")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::RuleAlreadyExists(msg) => {
write!(f, "RuleAlreadyExists")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
}
}
}
pub struct AddRuleResponse;
impl jacquard_common::xrpc::XrpcResp for AddRuleResponse {
const NSID: &'static str = "tools.ozone.safelink.addRule";
const ENCODING: &'static str = "application/json";
type Output<'de> = AddRuleOutput<'de>;
type Err<'de> = AddRuleError<'de>;
}
impl<'a> jacquard_common::xrpc::XrpcRequest for AddRule<'a> {
const NSID: &'static str = "tools.ozone.safelink.addRule";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = AddRuleResponse;
}
pub struct AddRuleRequest;
impl jacquard_common::xrpc::XrpcEndpoint for AddRuleRequest {
const PATH: &'static str = "/xrpc/tools.ozone.safelink.addRule";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<'de> = AddRule<'de>;
type Response = AddRuleResponse;
}
pub mod add_rule_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Url;
type Action;
type Reason;
type Pattern;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Url = Unset;
type Action = Unset;
type Reason = Unset;
type Pattern = Unset;
}
pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetUrl<S> {}
impl<S: State> State for SetUrl<S> {
type Url = Set<members::url>;
type Action = S::Action;
type Reason = S::Reason;
type Pattern = S::Pattern;
}
pub struct SetAction<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAction<S> {}
impl<S: State> State for SetAction<S> {
type Url = S::Url;
type Action = Set<members::action>;
type Reason = S::Reason;
type Pattern = S::Pattern;
}
pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetReason<S> {}
impl<S: State> State for SetReason<S> {
type Url = S::Url;
type Action = S::Action;
type Reason = Set<members::reason>;
type Pattern = S::Pattern;
}
pub struct SetPattern<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPattern<S> {}
impl<S: State> State for SetPattern<S> {
type Url = S::Url;
type Action = S::Action;
type Reason = S::Reason;
type Pattern = Set<members::pattern>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct url(());
pub struct action(());
pub struct reason(());
pub struct pattern(());
}
}
pub struct AddRuleBuilder<'a, S: add_rule_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<ActionType<'a>>,
Option<CowStr<'a>>,
Option<Did<'a>>,
Option<PatternType<'a>>,
Option<ReasonType<'a>>,
Option<CowStr<'a>>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> AddRule<'a> {
pub fn new() -> AddRuleBuilder<'a, add_rule_state::Empty> {
AddRuleBuilder::new()
}
}
impl<'a> AddRuleBuilder<'a, add_rule_state::Empty> {
pub fn new() -> Self {
AddRuleBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> AddRuleBuilder<'a, S>
where
S: add_rule_state::State,
S::Action: add_rule_state::IsUnset,
{
pub fn action(
mut self,
value: impl Into<ActionType<'a>>,
) -> AddRuleBuilder<'a, add_rule_state::SetAction<S>> {
self._fields.0 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: add_rule_state::State> AddRuleBuilder<'a, S> {
pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.1 = value;
self
}
}
impl<'a, S: add_rule_state::State> AddRuleBuilder<'a, S> {
pub fn created_by(mut self, value: impl Into<Option<Did<'a>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_created_by(mut self, value: Option<Did<'a>>) -> Self {
self._fields.2 = value;
self
}
}
impl<'a, S> AddRuleBuilder<'a, S>
where
S: add_rule_state::State,
S::Pattern: add_rule_state::IsUnset,
{
pub fn pattern(
mut self,
value: impl Into<PatternType<'a>>,
) -> AddRuleBuilder<'a, add_rule_state::SetPattern<S>> {
self._fields.3 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AddRuleBuilder<'a, S>
where
S: add_rule_state::State,
S::Reason: add_rule_state::IsUnset,
{
pub fn reason(
mut self,
value: impl Into<ReasonType<'a>>,
) -> AddRuleBuilder<'a, add_rule_state::SetReason<S>> {
self._fields.4 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AddRuleBuilder<'a, S>
where
S: add_rule_state::State,
S::Url: add_rule_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<CowStr<'a>>,
) -> AddRuleBuilder<'a, add_rule_state::SetUrl<S>> {
self._fields.5 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AddRuleBuilder<'a, S>
where
S: add_rule_state::State,
S::Url: add_rule_state::IsSet,
S::Action: add_rule_state::IsSet,
S::Reason: add_rule_state::IsSet,
S::Pattern: add_rule_state::IsSet,
{
pub fn build(self) -> AddRule<'a> {
AddRule {
action: self._fields.0.unwrap(),
comment: self._fields.1,
created_by: self._fields.2,
pattern: self._fields.3.unwrap(),
reason: self._fields.4.unwrap(),
url: self._fields.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> AddRule<'a> {
AddRule {
action: self._fields.0.unwrap(),
comment: self._fields.1,
created_by: self._fields.2,
pattern: self._fields.3.unwrap(),
reason: self._fields.4.unwrap(),
url: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}