// @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, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{Did, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use serde::{Serialize, Deserialize};
use crate::tools_ozone::moderation::ScheduledActionView;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListScheduledActions<S: BosStr = DefaultStr> {
    ///Cursor for pagination
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    ///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
    pub statuses: Vec<S>,
    ///Filter actions for specific DID subjects
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subjects: Option<Vec<Did<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 ListScheduledActionsOutput<S: BosStr = DefaultStr> {
    pub actions: Vec<ScheduledActionView<S>>,
    ///Cursor for next page of results
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `tools.ozone.moderation.listScheduledActions` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ListScheduledActionsOutput<S>` for this endpoint.*/
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<S: BosStr> = ListScheduledActionsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ListScheduledActions<S> {
    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 marker for the `tools.ozone.moderation.listScheduledActions` procedure.

Path: `/xrpc/tools.ozone.moderation.listScheduledActions`. The request payload type is `ListScheduledActions<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
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<S: BosStr> = ListScheduledActions<S>;
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStatuses<St> {}
    impl<St: State> State for SetStatuses<St> {
        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<
    St: list_scheduled_actions_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<Datetime>,
        Option<i64>,
        Option<Datetime>,
        Option<Vec<S>>,
        Option<Vec<Did<S>>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<
    St: list_scheduled_actions_state::State,
    S: BosStr,
> ListScheduledActionsBuilder<St, 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<
    St: list_scheduled_actions_state::State,
    S: BosStr,
> ListScheduledActionsBuilder<St, 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<
    St: list_scheduled_actions_state::State,
    S: BosStr,
> ListScheduledActionsBuilder<St, 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<St, S: BosStr> ListScheduledActionsBuilder<St, S>
where
    St: list_scheduled_actions_state::State,
    St::Statuses: list_scheduled_actions_state::IsUnset,
{
    /// Set the `statuses` field (required)
    pub fn statuses(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> ListScheduledActionsBuilder<list_scheduled_actions_state::SetStatuses<St>, S> {
        self._fields.4 = Option::Some(value.into());
        ListScheduledActionsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<
    St: list_scheduled_actions_state::State,
    S: BosStr,
> ListScheduledActionsBuilder<St, S> {
    /// Set the `subjects` field (optional)
    pub fn subjects(mut self, value: impl Into<Option<Vec<Did<S>>>>) -> 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<S>>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St, S: BosStr> ListScheduledActionsBuilder<St, S>
where
    St: list_scheduled_actions_state::State,
    St::Statuses: list_scheduled_actions_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListScheduledActions<S> {
        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<SmolStr, Data<S>>,
    ) -> ListScheduledActions<S> {
        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),
        }
    }
}