#[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;
use serde::{Serialize, Deserialize};
use crate::tools_ozone::setting::DefsOption;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpsertOption<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub key: Nsid<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub manager_role: Option<UpsertOptionManagerRole<S>>,
pub scope: UpsertOptionScope<S>,
pub value: Data<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpsertOptionManagerRole<S: BosStr = DefaultStr> {
RoleModerator,
RoleTriage,
RoleVerifier,
RoleAdmin,
Other(S),
}
impl<S: BosStr> UpsertOptionManagerRole<S> {
pub fn as_str(&self) -> &str {
match self {
Self::RoleModerator => "tools.ozone.team.defs#roleModerator",
Self::RoleTriage => "tools.ozone.team.defs#roleTriage",
Self::RoleVerifier => "tools.ozone.team.defs#roleVerifier",
Self::RoleAdmin => "tools.ozone.team.defs#roleAdmin",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"tools.ozone.team.defs#roleModerator" => Self::RoleModerator,
"tools.ozone.team.defs#roleTriage" => Self::RoleTriage,
"tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier,
"tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for UpsertOptionManagerRole<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for UpsertOptionManagerRole<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for UpsertOptionManagerRole<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for UpsertOptionManagerRole<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for UpsertOptionManagerRole<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for UpsertOptionManagerRole<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = UpsertOptionManagerRole<S::Output>;
fn into_static(self) -> Self::Output {
match self {
UpsertOptionManagerRole::RoleModerator => {
UpsertOptionManagerRole::RoleModerator
}
UpsertOptionManagerRole::RoleTriage => UpsertOptionManagerRole::RoleTriage,
UpsertOptionManagerRole::RoleVerifier => {
UpsertOptionManagerRole::RoleVerifier
}
UpsertOptionManagerRole::RoleAdmin => UpsertOptionManagerRole::RoleAdmin,
UpsertOptionManagerRole::Other(v) => {
UpsertOptionManagerRole::Other(v.into_static())
}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum UpsertOptionScope<S: BosStr = DefaultStr> {
Instance,
Personal,
Other(S),
}
impl<S: BosStr> UpsertOptionScope<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Instance => "instance",
Self::Personal => "personal",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"instance" => Self::Instance,
"personal" => Self::Personal,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for UpsertOptionScope<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for UpsertOptionScope<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for UpsertOptionScope<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for UpsertOptionScope<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for UpsertOptionScope<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for UpsertOptionScope<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = UpsertOptionScope<S::Output>;
fn into_static(self) -> Self::Output {
match self {
UpsertOptionScope::Instance => UpsertOptionScope::Instance,
UpsertOptionScope::Personal => UpsertOptionScope::Personal,
UpsertOptionScope::Other(v) => UpsertOptionScope::Other(v.into_static()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpsertOptionOutput<S: BosStr = DefaultStr> {
pub option: DefsOption<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
pub struct UpsertOptionResponse;
impl jacquard_common::xrpc::XrpcResp for UpsertOptionResponse {
const NSID: &'static str = "tools.ozone.setting.upsertOption";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = UpsertOptionOutput<S>;
type Err = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for UpsertOption<S> {
const NSID: &'static str = "tools.ozone.setting.upsertOption";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = UpsertOptionResponse;
}
pub struct UpsertOptionRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpsertOptionRequest {
const PATH: &'static str = "/xrpc/tools.ozone.setting.upsertOption";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = UpsertOption<S>;
type Response = UpsertOptionResponse;
}
pub mod upsert_option_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 Scope;
type Value;
type Key;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Scope = Unset;
type Value = Unset;
type Key = Unset;
}
pub struct SetScope<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetScope<St> {}
impl<St: State> State for SetScope<St> {
type Scope = Set<members::scope>;
type Value = St::Value;
type Key = St::Key;
}
pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetValue<St> {}
impl<St: State> State for SetValue<St> {
type Scope = St::Scope;
type Value = Set<members::value>;
type Key = St::Key;
}
pub struct SetKey<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetKey<St> {}
impl<St: State> State for SetKey<St> {
type Scope = St::Scope;
type Value = St::Value;
type Key = Set<members::key>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct scope(());
pub struct value(());
pub struct key(());
}
}
pub struct UpsertOptionBuilder<S: BosStr, St: upsert_option_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<Nsid<S>>,
Option<UpsertOptionManagerRole<S>>,
Option<UpsertOptionScope<S>>,
Option<Data<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> UpsertOption<S> {
pub fn new() -> UpsertOptionBuilder<S, upsert_option_state::Empty> {
UpsertOptionBuilder::new()
}
}
impl<S: BosStr> UpsertOptionBuilder<S, upsert_option_state::Empty> {
pub fn new() -> Self {
UpsertOptionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: upsert_option_state::State> UpsertOptionBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> UpsertOptionBuilder<S, St>
where
St: upsert_option_state::State,
St::Key: upsert_option_state::IsUnset,
{
pub fn key(
mut self,
value: impl Into<Nsid<S>>,
) -> UpsertOptionBuilder<S, upsert_option_state::SetKey<St>> {
self._fields.1 = Option::Some(value.into());
UpsertOptionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: upsert_option_state::State> UpsertOptionBuilder<S, St> {
pub fn manager_role(
mut self,
value: impl Into<Option<UpsertOptionManagerRole<S>>>,
) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_manager_role(
mut self,
value: Option<UpsertOptionManagerRole<S>>,
) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St> UpsertOptionBuilder<S, St>
where
St: upsert_option_state::State,
St::Scope: upsert_option_state::IsUnset,
{
pub fn scope(
mut self,
value: impl Into<UpsertOptionScope<S>>,
) -> UpsertOptionBuilder<S, upsert_option_state::SetScope<St>> {
self._fields.3 = Option::Some(value.into());
UpsertOptionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UpsertOptionBuilder<S, St>
where
St: upsert_option_state::State,
St::Value: upsert_option_state::IsUnset,
{
pub fn value(
mut self,
value: impl Into<Data<S>>,
) -> UpsertOptionBuilder<S, upsert_option_state::SetValue<St>> {
self._fields.4 = Option::Some(value.into());
UpsertOptionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> UpsertOptionBuilder<S, St>
where
St: upsert_option_state::State,
St::Scope: upsert_option_state::IsSet,
St::Value: upsert_option_state::IsSet,
St::Key: upsert_option_state::IsSet,
{
pub fn build(self) -> UpsertOption<S> {
UpsertOption {
description: self._fields.0,
key: self._fields.1.unwrap(),
manager_role: self._fields.2,
scope: self._fields.3.unwrap(),
value: self._fields.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> UpsertOption<S> {
UpsertOption {
description: self._fields.0,
key: self._fields.1.unwrap(),
manager_role: self._fields.2,
scope: self._fields.3.unwrap(),
value: self._fields.4.unwrap(),
extra_data: Some(extra_data),
}
}
}