jacquard-api 0.12.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.report.createActivity
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[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::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::report::AssignmentActivity;
use crate::tools_ozone::report::CloseActivity;
use crate::tools_ozone::report::EscalationActivity;
use crate::tools_ozone::report::NoteActivity;
use crate::tools_ozone::report::QueueActivity;
use crate::tools_ozone::report::ReopenActivity;
use crate::tools_ozone::report::ReportActivityView;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateActivity<S: BosStr = DefaultStr> {
    ///The type of activity to record.
    pub activity: CreateActivityActivity<S>,
    ///Optional moderator-only note. Not visible to reporters.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub internal_note: Option<S>,
    ///Set true when this activity is triggered by an automated process. Defaults to false.  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_create_activity_is_automated")]
    pub is_automated: Option<bool>,
    ///Optional public-facing note, potentially visible to the reporter.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub public_note: Option<S>,
    ///ID of the report to record activity on
    pub report_id: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CreateActivityActivity<S: BosStr = DefaultStr> {
    #[serde(rename = "tools.ozone.report.defs#queueActivity")]
    QueueActivity(Box<QueueActivity<S>>),
    #[serde(rename = "tools.ozone.report.defs#assignmentActivity")]
    AssignmentActivity(Box<AssignmentActivity<S>>),
    #[serde(rename = "tools.ozone.report.defs#escalationActivity")]
    EscalationActivity(Box<EscalationActivity<S>>),
    #[serde(rename = "tools.ozone.report.defs#closeActivity")]
    CloseActivity(Box<CloseActivity<S>>),
    #[serde(rename = "tools.ozone.report.defs#reopenActivity")]
    ReopenActivity(Box<ReopenActivity<S>>),
    #[serde(rename = "tools.ozone.report.defs#noteActivity")]
    NoteActivity(Box<NoteActivity<S>>),
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateActivityOutput<S: BosStr = DefaultStr> {
    pub activity: ReportActivityView<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 CreateActivityError {
    /// No report exists with the given reportId
    #[serde(rename = "ReportNotFound")]
    ReportNotFound(Option<SmolStr>),
    /// The requested state transition is not permitted from the report's current status
    #[serde(rename = "InvalidStateTransition")]
    InvalidStateTransition(Option<SmolStr>),
    /// The report is already in the status implied by this activity type
    #[serde(rename = "AlreadyInTargetState")]
    AlreadyInTargetState(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for CreateActivityError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::ReportNotFound(msg) => {
                write!(f, "ReportNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::InvalidStateTransition(msg) => {
                write!(f, "InvalidStateTransition")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::AlreadyInTargetState(msg) => {
                write!(f, "AlreadyInTargetState")?;
                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(())
            }
        }
    }
}

/** Response marker for the `tools.ozone.report.createActivity` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `CreateActivityOutput<S>` for this endpoint.*/
pub struct CreateActivityResponse;
impl jacquard_common::xrpc::XrpcResp for CreateActivityResponse {
    const NSID: &'static str = "tools.ozone.report.createActivity";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = CreateActivityOutput<S>;
    type Err = CreateActivityError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateActivity<S> {
    const NSID: &'static str = "tools.ozone.report.createActivity";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = CreateActivityResponse;
}

/** Endpoint marker for the `tools.ozone.report.createActivity` procedure.

Path: `/xrpc/tools.ozone.report.createActivity`. The request payload type is `CreateActivity<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct CreateActivityRequest;
impl jacquard_common::xrpc::XrpcEndpoint for CreateActivityRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.report.createActivity";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = CreateActivity<S>;
    type Response = CreateActivityResponse;
}

fn _default_create_activity_is_automated() -> Option<bool> {
    Some(false)
}

pub mod create_activity_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Activity;
        type ReportId;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Activity = Unset;
        type ReportId = Unset;
    }
    ///State transition - sets the `activity` field to Set
    pub struct SetActivity<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActivity<St> {}
    impl<St: State> State for SetActivity<St> {
        type Activity = Set<members::activity>;
        type ReportId = St::ReportId;
    }
    ///State transition - sets the `report_id` field to Set
    pub struct SetReportId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReportId<St> {}
    impl<St: State> State for SetReportId<St> {
        type Activity = St::Activity;
        type ReportId = Set<members::report_id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `activity` field
        pub struct activity(());
        ///Marker type for the `report_id` field
        pub struct report_id(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CreateActivityBuilder<
    St: create_activity_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<CreateActivityActivity<S>>,
        Option<S>,
        Option<bool>,
        Option<S>,
        Option<i64>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl CreateActivity<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> CreateActivityBuilder<create_activity_state::Empty, DefaultStr> {
        CreateActivityBuilder::new()
    }
}

impl<S: BosStr> CreateActivity<S> {
    /// Create a new builder for this type
    pub fn builder() -> CreateActivityBuilder<create_activity_state::Empty, S> {
        CreateActivityBuilder::builder()
    }
}

impl CreateActivityBuilder<create_activity_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        CreateActivityBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> CreateActivityBuilder<create_activity_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        CreateActivityBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateActivityBuilder<St, S>
where
    St: create_activity_state::State,
    St::Activity: create_activity_state::IsUnset,
{
    /// Set the `activity` field (required)
    pub fn activity(
        mut self,
        value: impl Into<CreateActivityActivity<S>>,
    ) -> CreateActivityBuilder<create_activity_state::SetActivity<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CreateActivityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: create_activity_state::State, S: BosStr> CreateActivityBuilder<St, S> {
    /// Set the `internalNote` field (optional)
    pub fn internal_note(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `internalNote` field to an Option value (optional)
    pub fn maybe_internal_note(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: create_activity_state::State, S: BosStr> CreateActivityBuilder<St, S> {
    /// Set the `isAutomated` field (optional)
    pub fn is_automated(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `isAutomated` field to an Option value (optional)
    pub fn maybe_is_automated(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: create_activity_state::State, S: BosStr> CreateActivityBuilder<St, S> {
    /// Set the `publicNote` field (optional)
    pub fn public_note(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `publicNote` field to an Option value (optional)
    pub fn maybe_public_note(mut self, value: Option<S>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> CreateActivityBuilder<St, S>
where
    St: create_activity_state::State,
    St::ReportId: create_activity_state::IsUnset,
{
    /// Set the `reportId` field (required)
    pub fn report_id(
        mut self,
        value: impl Into<i64>,
    ) -> CreateActivityBuilder<create_activity_state::SetReportId<St>, S> {
        self._fields.4 = Option::Some(value.into());
        CreateActivityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateActivityBuilder<St, S>
where
    St: create_activity_state::State,
    St::Activity: create_activity_state::IsSet,
    St::ReportId: create_activity_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CreateActivity<S> {
        CreateActivity {
            activity: self._fields.0.unwrap(),
            internal_note: self._fields.1,
            is_automated: self._fields.2.or_else(|| Some(false)),
            public_note: self._fields.3,
            report_id: self._fields.4.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> CreateActivity<S> {
        CreateActivity {
            activity: self._fields.0.unwrap(),
            internal_note: self._fields.1,
            is_automated: self._fields.2.or_else(|| Some(false)),
            public_note: self._fields.3,
            report_id: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}