#[allow(unused_imports)]
use alloc::collections::BTreeMap;
use crate::tools_ozone::safelink::ActionType;
use crate::tools_ozone::safelink::Event;
use crate::tools_ozone::safelink::PatternType;
use crate::tools_ozone::safelink::ReasonType;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::Did;
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::{IntoStatic, open_union};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct AddRule<S: BosStr = DefaultStr> {
pub action: ActionType<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comment: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub created_by: Option<Did<S>>,
pub pattern: PatternType<S>,
pub reason: ReasonType<S>,
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 AddRuleOutput<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 AddRuleError {
#[serde(rename = "InvalidUrl")]
InvalidUrl(Option<SmolStr>),
#[serde(rename = "RuleAlreadyExists")]
RuleAlreadyExists(Option<SmolStr>),
#[serde(untagged)]
Other {
error: SmolStr,
message: Option<SmolStr>,
},
}
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::Other { error, message } => {
write!(f, "{}", error)?;
if let Some(msg) = message {
write!(f, ": {}", msg)?;
}
Ok(())
}
}
}
}
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<S: BosStr> = AddRuleOutput<S>;
type Err = AddRuleError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for AddRule<S> {
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<S: BosStr> = AddRule<S>;
type Response = AddRuleResponse;
}
pub mod add_rule_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Action;
type Reason;
type Url;
type Pattern;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Action = Unset;
type Reason = Unset;
type Url = Unset;
type Pattern = Unset;
}
pub struct SetAction<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAction<St> {}
impl<St: State> State for SetAction<St> {
type Action = Set<members::action>;
type Reason = St::Reason;
type Url = St::Url;
type Pattern = St::Pattern;
}
pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetReason<St> {}
impl<St: State> State for SetReason<St> {
type Action = St::Action;
type Reason = Set<members::reason>;
type Url = St::Url;
type Pattern = St::Pattern;
}
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 Action = St::Action;
type Reason = St::Reason;
type Url = Set<members::url>;
type Pattern = St::Pattern;
}
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 Action = St::Action;
type Reason = St::Reason;
type Url = St::Url;
type Pattern = Set<members::pattern>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct action(());
pub struct reason(());
pub struct url(());
pub struct pattern(());
}
}
pub struct AddRuleBuilder<S: BosStr, St: add_rule_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<ActionType<S>>,
Option<S>,
Option<Did<S>>,
Option<PatternType<S>>,
Option<ReasonType<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> AddRule<S> {
pub fn new() -> AddRuleBuilder<S, add_rule_state::Empty> {
AddRuleBuilder::new()
}
}
impl<S: BosStr> AddRuleBuilder<S, add_rule_state::Empty> {
pub fn new() -> Self {
AddRuleBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AddRuleBuilder<S, St>
where
St: add_rule_state::State,
St::Action: add_rule_state::IsUnset,
{
pub fn action(
mut self,
value: impl Into<ActionType<S>>,
) -> AddRuleBuilder<S, add_rule_state::SetAction<St>> {
self._fields.0 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: add_rule_state::State> AddRuleBuilder<S, St> {
pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_comment(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: add_rule_state::State> AddRuleBuilder<S, St> {
pub fn created_by(mut self, value: impl Into<Option<Did<S>>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_created_by(mut self, value: Option<Did<S>>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> AddRuleBuilder<S, St>
where
St: add_rule_state::State,
St::Pattern: add_rule_state::IsUnset,
{
pub fn pattern(
mut self,
value: impl Into<PatternType<S>>,
) -> AddRuleBuilder<S, add_rule_state::SetPattern<St>> {
self._fields.3 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AddRuleBuilder<S, St>
where
St: add_rule_state::State,
St::Reason: add_rule_state::IsUnset,
{
pub fn reason(
mut self,
value: impl Into<ReasonType<S>>,
) -> AddRuleBuilder<S, add_rule_state::SetReason<St>> {
self._fields.4 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AddRuleBuilder<S, St>
where
St: add_rule_state::State,
St::Url: add_rule_state::IsUnset,
{
pub fn url(mut self, value: impl Into<S>) -> AddRuleBuilder<S, add_rule_state::SetUrl<St>> {
self._fields.5 = Option::Some(value.into());
AddRuleBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> AddRuleBuilder<S, St>
where
St: add_rule_state::State,
St::Action: add_rule_state::IsSet,
St::Reason: add_rule_state::IsSet,
St::Url: add_rule_state::IsSet,
St::Pattern: add_rule_state::IsSet,
{
pub fn build(self) -> AddRule<S> {
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<SmolStr, Data<S>>) -> AddRule<S> {
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),
}
}
}