// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.moderation.listScheduledActions
//
// 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;
use jacquard_common::types::string::{Did, Datetime};
use jacquard_derive::{IntoStatic, lexicon};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::moderation::ScheduledActionView;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListScheduledActions<'a> {
    ///Cursor for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///Filter actions scheduled to execute before this time
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ends_before: Option<Datetime>,
    ///Maximum number of results to return  Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_list_scheduled_actions_limit")]
    pub limit: Option<i64>,
    ///Filter actions scheduled to execute after this time
    #[serde(skip_serializing_if = "Option::is_none")]
    pub starts_after: Option<Datetime>,
    ///Filter actions by status
    #[serde(borrow)]
    pub statuses: Vec<CowStr<'a>>,
    ///Filter actions for specific DID subjects
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub subjects: Option<Vec<Did<'a>>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListScheduledActionsOutput<'a> {
    #[serde(borrow)]
    pub actions: Vec<ScheduledActionView<'a>>,
    ///Cursor for next page of results
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
}

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

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

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

fn _default_list_scheduled_actions_limit() -> Option<i64> {
    Some(50i64)
}

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

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

impl<'a> ListScheduledActions<'a> {
    /// Create a new builder for this type
    pub fn new() -> ListScheduledActionsBuilder<
        'a,
        list_scheduled_actions_state::Empty,
    > {
        ListScheduledActionsBuilder::new()
    }
}

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

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

impl<'a, S: list_scheduled_actions_state::State> ListScheduledActionsBuilder<'a, S> {
    /// Set the `endsBefore` field (optional)
    pub fn ends_before(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `endsBefore` field to an Option value (optional)
    pub fn maybe_ends_before(mut self, value: Option<Datetime>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: list_scheduled_actions_state::State> ListScheduledActionsBuilder<'a, S> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: list_scheduled_actions_state::State> ListScheduledActionsBuilder<'a, S> {
    /// Set the `startsAfter` field (optional)
    pub fn starts_after(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `startsAfter` field to an Option value (optional)
    pub fn maybe_starts_after(mut self, value: Option<Datetime>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> ListScheduledActionsBuilder<'a, S>
where
    S: list_scheduled_actions_state::State,
    S::Statuses: list_scheduled_actions_state::IsUnset,
{
    /// Set the `statuses` field (required)
    pub fn statuses(
        mut self,
        value: impl Into<Vec<CowStr<'a>>>,
    ) -> ListScheduledActionsBuilder<'a, list_scheduled_actions_state::SetStatuses<S>> {
        self._fields.4 = Option::Some(value.into());
        ListScheduledActionsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: list_scheduled_actions_state::State> ListScheduledActionsBuilder<'a, S> {
    /// Set the `subjects` field (optional)
    pub fn subjects(mut self, value: impl Into<Option<Vec<Did<'a>>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `subjects` field to an Option value (optional)
    pub fn maybe_subjects(mut self, value: Option<Vec<Did<'a>>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S> ListScheduledActionsBuilder<'a, S>
where
    S: list_scheduled_actions_state::State,
    S::Statuses: list_scheduled_actions_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ListScheduledActions<'a> {
        ListScheduledActions {
            cursor: self._fields.0,
            ends_before: self._fields.1,
            limit: self._fields.2.or_else(|| Some(50i64)),
            starts_after: self._fields.3,
            statuses: self._fields.4.unwrap(),
            subjects: self._fields.5,
            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>,
        >,
    ) -> ListScheduledActions<'a> {
        ListScheduledActions {
            cursor: self._fields.0,
            ends_before: self._fields.1,
            limit: self._fields.2.or_else(|| Some(50i64)),
            starts_after: self._fields.3,
            statuses: self._fields.4.unwrap(),
            subjects: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}