1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: tools.ozone.safelink.addRule
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[jacquard_derive::lexicon]
9#[derive(
10 serde::Serialize,
11 serde::Deserialize,
12 Debug,
13 Clone,
14 PartialEq,
15 Eq,
16 bon::Builder
17)]
18#[serde(rename_all = "camelCase")]
19#[builder(start_fn = new)]
20pub struct AddRule<'a> {
21 #[serde(borrow)]
22 pub action: crate::tools_ozone::safelink::ActionType<'a>,
23 ///Optional comment about the decision
24 #[serde(skip_serializing_if = "std::option::Option::is_none")]
25 #[serde(borrow)]
26 #[builder(into)]
27 pub comment: std::option::Option<jacquard_common::CowStr<'a>>,
28 ///Author DID. Only respected when using admin auth
29 #[serde(skip_serializing_if = "std::option::Option::is_none")]
30 #[serde(borrow)]
31 pub created_by: std::option::Option<jacquard_common::types::string::Did<'a>>,
32 #[serde(borrow)]
33 pub pattern: crate::tools_ozone::safelink::PatternType<'a>,
34 #[serde(borrow)]
35 pub reason: crate::tools_ozone::safelink::ReasonType<'a>,
36 ///The URL or domain to apply the rule to
37 #[serde(borrow)]
38 #[builder(into)]
39 pub url: jacquard_common::CowStr<'a>,
40 #[serde(flatten)]
41 #[serde(borrow)]
42 #[builder(default)]
43 pub extra_data: ::std::collections::BTreeMap<
44 ::jacquard_common::smol_str::SmolStr,
45 ::jacquard_common::types::value::Data<'a>,
46 >,
47}
48
49impl jacquard_common::IntoStatic for AddRule<'_> {
50 type Output = AddRule<'static>;
51 fn into_static(self) -> Self::Output {
52 AddRule {
53 action: self.action.into_static(),
54 comment: self.comment.into_static(),
55 created_by: self.created_by.into_static(),
56 pattern: self.pattern.into_static(),
57 reason: self.reason.into_static(),
58 url: self.url.into_static(),
59 extra_data: self.extra_data.into_static(),
60 }
61 }
62}
63
64#[jacquard_derive::lexicon]
65#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq, Eq)]
66#[serde(rename_all = "camelCase")]
67pub struct AddRuleOutput<'a> {
68 #[serde(flatten)]
69 #[serde(borrow)]
70 pub value: crate::tools_ozone::safelink::Event<'a>,
71}
72
73impl jacquard_common::IntoStatic for AddRuleOutput<'_> {
74 type Output = AddRuleOutput<'static>;
75 fn into_static(self) -> Self::Output {
76 AddRuleOutput {
77 value: self.value.into_static(),
78 extra_data: self.extra_data.into_static(),
79 }
80 }
81}
82
83#[jacquard_derive::open_union]
84#[derive(
85 serde::Serialize,
86 serde::Deserialize,
87 Debug,
88 Clone,
89 PartialEq,
90 Eq,
91 thiserror::Error,
92 miette::Diagnostic
93)]
94#[serde(tag = "error", content = "message")]
95#[serde(bound(deserialize = "'de: 'a"))]
96pub enum AddRuleError<'a> {
97 ///The provided URL is invalid
98 #[serde(rename = "InvalidUrl")]
99 InvalidUrl(std::option::Option<String>),
100 ///A rule for this URL/domain already exists
101 #[serde(rename = "RuleAlreadyExists")]
102 RuleAlreadyExists(std::option::Option<String>),
103}
104
105impl std::fmt::Display for AddRuleError<'_> {
106 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
107 match self {
108 Self::InvalidUrl(msg) => {
109 write!(f, "InvalidUrl")?;
110 if let Some(msg) = msg {
111 write!(f, ": {}", msg)?;
112 }
113 Ok(())
114 }
115 Self::RuleAlreadyExists(msg) => {
116 write!(f, "RuleAlreadyExists")?;
117 if let Some(msg) = msg {
118 write!(f, ": {}", msg)?;
119 }
120 Ok(())
121 }
122 Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
123 }
124 }
125}
126
127impl jacquard_common::IntoStatic for AddRuleError<'_> {
128 type Output = AddRuleError<'static>;
129 fn into_static(self) -> Self::Output {
130 match self {
131 AddRuleError::InvalidUrl(v) => AddRuleError::InvalidUrl(v.into_static()),
132 AddRuleError::RuleAlreadyExists(v) => {
133 AddRuleError::RuleAlreadyExists(v.into_static())
134 }
135 AddRuleError::Unknown(v) => AddRuleError::Unknown(v.into_static()),
136 }
137 }
138}
139
140impl jacquard_common::types::xrpc::XrpcRequest for AddRule<'_> {
141 const NSID: &'static str = "tools.ozone.safelink.addRule";
142 const METHOD: jacquard_common::types::xrpc::XrpcMethod = jacquard_common::types::xrpc::XrpcMethod::Procedure(
143 "application/json",
144 );
145 const OUTPUT_ENCODING: &'static str = "application/json";
146 type Output<'de> = AddRuleOutput<'de>;
147 type Err<'de> = AddRuleError<'de>;
148}