#[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::Nsid;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::queue::QueueView;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateQueue<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub collection: Option<Nsid<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub name: S,
pub report_types: Vec<S>,
pub subject_types: Vec<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 CreateQueueOutput<S: BosStr = DefaultStr> {
pub queue: QueueView<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 CreateQueueError {
#[serde(rename = "ConflictingQueue")]
ConflictingQueue(Option<SmolStr>),
#[serde(untagged)]
Other { error: SmolStr, message: Option<SmolStr> },
}
impl core::fmt::Display for CreateQueueError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ConflictingQueue(msg) => {
write!(f, "ConflictingQueue")?;
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 CreateQueueResponse;
impl jacquard_common::xrpc::XrpcResp for CreateQueueResponse {
const NSID: &'static str = "tools.ozone.queue.createQueue";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CreateQueueOutput<S>;
type Err = CreateQueueError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateQueue<S> {
const NSID: &'static str = "tools.ozone.queue.createQueue";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = CreateQueueResponse;
}
pub struct CreateQueueRequest;
impl jacquard_common::xrpc::XrpcEndpoint for CreateQueueRequest {
const PATH: &'static str = "/xrpc/tools.ozone.queue.createQueue";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = CreateQueue<S>;
type Response = CreateQueueResponse;
}
pub mod create_queue_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 Name;
type ReportTypes;
type SubjectTypes;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Name = Unset;
type ReportTypes = Unset;
type SubjectTypes = Unset;
}
pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetName<St> {}
impl<St: State> State for SetName<St> {
type Name = Set<members::name>;
type ReportTypes = St::ReportTypes;
type SubjectTypes = St::SubjectTypes;
}
pub struct SetReportTypes<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetReportTypes<St> {}
impl<St: State> State for SetReportTypes<St> {
type Name = St::Name;
type ReportTypes = Set<members::report_types>;
type SubjectTypes = St::SubjectTypes;
}
pub struct SetSubjectTypes<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSubjectTypes<St> {}
impl<St: State> State for SetSubjectTypes<St> {
type Name = St::Name;
type ReportTypes = St::ReportTypes;
type SubjectTypes = Set<members::subject_types>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct name(());
pub struct report_types(());
pub struct subject_types(());
}
}
pub struct CreateQueueBuilder<St: create_queue_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (Option<Nsid<S>>, Option<S>, Option<S>, Option<Vec<S>>, Option<Vec<S>>),
_type: PhantomData<fn() -> S>,
}
impl CreateQueue<DefaultStr> {
pub fn new() -> CreateQueueBuilder<create_queue_state::Empty, DefaultStr> {
CreateQueueBuilder::new()
}
}
impl<S: BosStr> CreateQueue<S> {
pub fn builder() -> CreateQueueBuilder<create_queue_state::Empty, S> {
CreateQueueBuilder::builder()
}
}
impl CreateQueueBuilder<create_queue_state::Empty, DefaultStr> {
pub fn new() -> Self {
CreateQueueBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> CreateQueueBuilder<create_queue_state::Empty, S> {
pub fn builder() -> Self {
CreateQueueBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St: create_queue_state::State, S: BosStr> CreateQueueBuilder<St, S> {
pub fn collection(mut self, value: impl Into<Option<Nsid<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_collection(mut self, value: Option<Nsid<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<St: create_queue_state::State, S: BosStr> CreateQueueBuilder<St, S> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<St, S: BosStr> CreateQueueBuilder<St, S>
where
St: create_queue_state::State,
St::Name: create_queue_state::IsUnset,
{
pub fn name(
mut self,
value: impl Into<S>,
) -> CreateQueueBuilder<create_queue_state::SetName<St>, S> {
self._fields.2 = Option::Some(value.into());
CreateQueueBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CreateQueueBuilder<St, S>
where
St: create_queue_state::State,
St::ReportTypes: create_queue_state::IsUnset,
{
pub fn report_types(
mut self,
value: impl Into<Vec<S>>,
) -> CreateQueueBuilder<create_queue_state::SetReportTypes<St>, S> {
self._fields.3 = Option::Some(value.into());
CreateQueueBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CreateQueueBuilder<St, S>
where
St: create_queue_state::State,
St::SubjectTypes: create_queue_state::IsUnset,
{
pub fn subject_types(
mut self,
value: impl Into<Vec<S>>,
) -> CreateQueueBuilder<create_queue_state::SetSubjectTypes<St>, S> {
self._fields.4 = Option::Some(value.into());
CreateQueueBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> CreateQueueBuilder<St, S>
where
St: create_queue_state::State,
St::Name: create_queue_state::IsSet,
St::ReportTypes: create_queue_state::IsSet,
St::SubjectTypes: create_queue_state::IsSet,
{
pub fn build(self) -> CreateQueue<S> {
CreateQueue {
collection: self._fields.0,
description: self._fields.1,
name: self._fields.2.unwrap(),
report_types: self._fields.3.unwrap(),
subject_types: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> CreateQueue<S> {
CreateQueue {
collection: self._fields.0,
description: self._fields.1,
name: self._fields.2.unwrap(),
report_types: self._fields.3.unwrap(),
subject_types: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}