// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.moderation.cancelScheduledActions
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::Did;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::moderation::cancel_scheduled_actions;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CancellationResults<'a> {
    ///DIDs for which cancellation failed with error details
    #[serde(borrow)]
    pub failed: Vec<cancel_scheduled_actions::FailedCancellation<'a>>,
    ///DIDs for which all pending scheduled actions were successfully cancelled
    #[serde(borrow)]
    pub succeeded: Vec<Did<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FailedCancellation<'a> {
    #[serde(borrow)]
    pub did: Did<'a>,
    #[serde(borrow)]
    pub error: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub error_code: Option<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CancelScheduledActions<'a> {
    ///Optional comment describing the reason for cancellation
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub comment: Option<CowStr<'a>>,
    ///Array of DID subjects to cancel scheduled actions for
    #[serde(borrow)]
    pub subjects: Vec<Did<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CancelScheduledActionsOutput<'a> {
    #[serde(flatten)]
    #[serde(borrow)]
    pub value: jacquard_common::types::value::Data<'a>,
}

impl<'a> LexiconSchema for CancellationResults<'a> {
    fn nsid() -> &'static str {
        "tools.ozone.moderation.cancelScheduledActions"
    }
    fn def_name() -> &'static str {
        "cancellationResults"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_moderation_cancelScheduledActions()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for FailedCancellation<'a> {
    fn nsid() -> &'static str {
        "tools.ozone.moderation.cancelScheduledActions"
    }
    fn def_name() -> &'static str {
        "failedCancellation"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_moderation_cancelScheduledActions()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Response type for tools.ozone.moderation.cancelScheduledActions
pub struct CancelScheduledActionsResponse;
impl jacquard_common::xrpc::XrpcResp for CancelScheduledActionsResponse {
    const NSID: &'static str = "tools.ozone.moderation.cancelScheduledActions";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = CancelScheduledActionsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for CancelScheduledActions<'a> {
    const NSID: &'static str = "tools.ozone.moderation.cancelScheduledActions";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = CancelScheduledActionsResponse;
}

/// Endpoint type for tools.ozone.moderation.cancelScheduledActions
pub struct CancelScheduledActionsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for CancelScheduledActionsRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.moderation.cancelScheduledActions";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = CancelScheduledActions<'de>;
    type Response = CancelScheduledActionsResponse;
}

pub mod cancellation_results_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 Succeeded;
        type Failed;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Succeeded = Unset;
        type Failed = Unset;
    }
    ///State transition - sets the `succeeded` field to Set
    pub struct SetSucceeded<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSucceeded<S> {}
    impl<S: State> State for SetSucceeded<S> {
        type Succeeded = Set<members::succeeded>;
        type Failed = S::Failed;
    }
    ///State transition - sets the `failed` field to Set
    pub struct SetFailed<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFailed<S> {}
    impl<S: State> State for SetFailed<S> {
        type Succeeded = S::Succeeded;
        type Failed = Set<members::failed>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `succeeded` field
        pub struct succeeded(());
        ///Marker type for the `failed` field
        pub struct failed(());
    }
}

/// Builder for constructing an instance of this type
pub struct CancellationResultsBuilder<'a, S: cancellation_results_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<cancel_scheduled_actions::FailedCancellation<'a>>>,
        Option<Vec<Did<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> CancellationResults<'a> {
    /// Create a new builder for this type
    pub fn new() -> CancellationResultsBuilder<'a, cancellation_results_state::Empty> {
        CancellationResultsBuilder::new()
    }
}

impl<'a> CancellationResultsBuilder<'a, cancellation_results_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        CancellationResultsBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CancellationResultsBuilder<'a, S>
where
    S: cancellation_results_state::State,
    S::Failed: cancellation_results_state::IsUnset,
{
    /// Set the `failed` field (required)
    pub fn failed(
        mut self,
        value: impl Into<Vec<cancel_scheduled_actions::FailedCancellation<'a>>>,
    ) -> CancellationResultsBuilder<'a, cancellation_results_state::SetFailed<S>> {
        self._fields.0 = Option::Some(value.into());
        CancellationResultsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CancellationResultsBuilder<'a, S>
where
    S: cancellation_results_state::State,
    S::Succeeded: cancellation_results_state::IsUnset,
{
    /// Set the `succeeded` field (required)
    pub fn succeeded(
        mut self,
        value: impl Into<Vec<Did<'a>>>,
    ) -> CancellationResultsBuilder<'a, cancellation_results_state::SetSucceeded<S>> {
        self._fields.1 = Option::Some(value.into());
        CancellationResultsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CancellationResultsBuilder<'a, S>
where
    S: cancellation_results_state::State,
    S::Succeeded: cancellation_results_state::IsSet,
    S::Failed: cancellation_results_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CancellationResults<'a> {
        CancellationResults {
            failed: self._fields.0.unwrap(),
            succeeded: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CancellationResults<'a> {
        CancellationResults {
            failed: self._fields.0.unwrap(),
            succeeded: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_tools_ozone_moderation_cancelScheduledActions() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("tools.ozone.moderation.cancelScheduledActions"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("cancellationResults"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("succeeded"),
                            SmolStr::new_static("failed")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("failed"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "DIDs for which cancellation failed with error details",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#failedCancellation"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("succeeded"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "DIDs for which all pending scheduled actions were successfully cancelled",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("failedCancellation"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("did"), SmolStr::new_static("error")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("error"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("errorCode"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(vec![SmolStr::new_static("subjects")]),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("comment"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static(
                                                    "Optional comment describing the reason for cancellation",
                                                ),
                                            ),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("subjects"),
                                        LexObjectProperty::Array(LexArray {
                                            description: Some(
                                                CowStr::new_static(
                                                    "Array of DID subjects to cancel scheduled actions for",
                                                ),
                                            ),
                                            items: LexArrayItem::String(LexString {
                                                format: Some(LexStringFormat::Did),
                                                ..Default::default()
                                            }),
                                            max_length: Some(100usize),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod failed_cancellation_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 Did;
        type Error;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Did = Unset;
        type Error = Unset;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        type Did = Set<members::did>;
        type Error = S::Error;
    }
    ///State transition - sets the `error` field to Set
    pub struct SetError<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetError<S> {}
    impl<S: State> State for SetError<S> {
        type Did = S::Did;
        type Error = Set<members::error>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `error` field
        pub struct error(());
    }
}

/// Builder for constructing an instance of this type
pub struct FailedCancellationBuilder<'a, S: failed_cancellation_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Did<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> FailedCancellation<'a> {
    /// Create a new builder for this type
    pub fn new() -> FailedCancellationBuilder<'a, failed_cancellation_state::Empty> {
        FailedCancellationBuilder::new()
    }
}

impl<'a> FailedCancellationBuilder<'a, failed_cancellation_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        FailedCancellationBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> FailedCancellationBuilder<'a, S>
where
    S: failed_cancellation_state::State,
    S::Did: failed_cancellation_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> FailedCancellationBuilder<'a, failed_cancellation_state::SetDid<S>> {
        self._fields.0 = Option::Some(value.into());
        FailedCancellationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> FailedCancellationBuilder<'a, S>
where
    S: failed_cancellation_state::State,
    S::Error: failed_cancellation_state::IsUnset,
{
    /// Set the `error` field (required)
    pub fn error(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> FailedCancellationBuilder<'a, failed_cancellation_state::SetError<S>> {
        self._fields.1 = Option::Some(value.into());
        FailedCancellationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: failed_cancellation_state::State> FailedCancellationBuilder<'a, S> {
    /// Set the `errorCode` field (optional)
    pub fn error_code(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `errorCode` field to an Option value (optional)
    pub fn maybe_error_code(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> FailedCancellationBuilder<'a, S>
where
    S: failed_cancellation_state::State,
    S::Did: failed_cancellation_state::IsSet,
    S::Error: failed_cancellation_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> FailedCancellation<'a> {
        FailedCancellation {
            did: self._fields.0.unwrap(),
            error: self._fields.1.unwrap(),
            error_code: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> FailedCancellation<'a> {
        FailedCancellation {
            did: self._fields.0.unwrap(),
            error: self._fields.1.unwrap(),
            error_code: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

pub mod cancel_scheduled_actions_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 Subjects;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Subjects = Unset;
    }
    ///State transition - sets the `subjects` field to Set
    pub struct SetSubjects<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubjects<S> {}
    impl<S: State> State for SetSubjects<S> {
        type Subjects = Set<members::subjects>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `subjects` field
        pub struct subjects(());
    }
}

/// Builder for constructing an instance of this type
pub struct CancelScheduledActionsBuilder<'a, S: cancel_scheduled_actions_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<Vec<Did<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> CancelScheduledActions<'a> {
    /// Create a new builder for this type
    pub fn new() -> CancelScheduledActionsBuilder<
        'a,
        cancel_scheduled_actions_state::Empty,
    > {
        CancelScheduledActionsBuilder::new()
    }
}

impl<'a> CancelScheduledActionsBuilder<'a, cancel_scheduled_actions_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        CancelScheduledActionsBuilder {
            _state: PhantomData,
            _fields: (None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: cancel_scheduled_actions_state::State> CancelScheduledActionsBuilder<'a, S> {
    /// Set the `comment` field (optional)
    pub fn comment(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `comment` field to an Option value (optional)
    pub fn maybe_comment(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> CancelScheduledActionsBuilder<'a, S>
where
    S: cancel_scheduled_actions_state::State,
    S::Subjects: cancel_scheduled_actions_state::IsUnset,
{
    /// Set the `subjects` field (required)
    pub fn subjects(
        mut self,
        value: impl Into<Vec<Did<'a>>>,
    ) -> CancelScheduledActionsBuilder<
        'a,
        cancel_scheduled_actions_state::SetSubjects<S>,
    > {
        self._fields.1 = Option::Some(value.into());
        CancelScheduledActionsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CancelScheduledActionsBuilder<'a, S>
where
    S: cancel_scheduled_actions_state::State,
    S::Subjects: cancel_scheduled_actions_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CancelScheduledActions<'a> {
        CancelScheduledActions {
            comment: self._fields.0,
            subjects: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CancelScheduledActions<'a> {
        CancelScheduledActions {
            comment: self._fields.0,
            subjects: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}