// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.edit.listDrafts
//
// 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};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::ident::AtIdentifier;
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::com_atproto::repo::strong_ref::StrongRef;
use crate::sh_weaver::edit::list_drafts;
/// Hydrated view of a draft with edit state.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DraftView<S: BosStr = DefaultStr> {
    pub cid: Cid<S>,
    pub created_at: Datetime,
    ///Associated edit root if one exists
    #[serde(skip_serializing_if = "Option::is_none")]
    pub edit_root: Option<StrongRef<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_edit_at: Option<Datetime>,
    ///Extracted title if available from edit state
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<S>,
    pub uri: AtUri<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 ListDrafts<S: BosStr = DefaultStr> {
    pub actor: AtIdentifier<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    /// Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListDraftsOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub drafts: Vec<list_drafts::DraftView<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for DraftView<S> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.listDrafts"
    }
    fn def_name() -> &'static str {
        "draftView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_listDrafts()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `sh.weaver.edit.listDrafts` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ListDraftsOutput<S>` for this endpoint.*/
pub struct ListDraftsResponse;
impl jacquard_common::xrpc::XrpcResp for ListDraftsResponse {
    const NSID: &'static str = "sh.weaver.edit.listDrafts";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ListDraftsOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ListDrafts<S> {
    const NSID: &'static str = "sh.weaver.edit.listDrafts";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = ListDraftsResponse;
}

/** Endpoint marker for the `sh.weaver.edit.listDrafts` query.

Path: `/xrpc/sh.weaver.edit.listDrafts`. The request payload type is `ListDrafts<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ListDraftsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListDraftsRequest {
    const PATH: &'static str = "/xrpc/sh.weaver.edit.listDrafts";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = ListDrafts<S>;
    type Response = ListDraftsResponse;
}

pub mod draft_view_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 Cid;
        type CreatedAt;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type CreatedAt = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCid<St> {}
    impl<St: State> State for SetCid<St> {
        type Cid = Set<members::cid>;
        type CreatedAt = St::CreatedAt;
        type Uri = St::Uri;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type Cid = St::Cid;
        type CreatedAt = Set<members::created_at>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Cid = St::Cid;
        type CreatedAt = St::CreatedAt;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct DraftViewBuilder<St: draft_view_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Cid<S>>,
        Option<Datetime>,
        Option<StrongRef<S>>,
        Option<Datetime>,
        Option<S>,
        Option<AtUri<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> DraftView<S> {
    /// Create a new builder for this type
    pub fn builder() -> DraftViewBuilder<draft_view_state::Empty, S> {
        DraftViewBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> DraftViewBuilder<St, S>
where
    St: draft_view_state::State,
    St::Cid: draft_view_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> DraftViewBuilder<draft_view_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        DraftViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DraftViewBuilder<St, S>
where
    St: draft_view_state::State,
    St::CreatedAt: draft_view_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> DraftViewBuilder<draft_view_state::SetCreatedAt<St>, S> {
        self._fields.1 = Option::Some(value.into());
        DraftViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: draft_view_state::State, S: BosStr> DraftViewBuilder<St, S> {
    /// Set the `editRoot` field (optional)
    pub fn edit_root(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `editRoot` field to an Option value (optional)
    pub fn maybe_edit_root(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: draft_view_state::State, S: BosStr> DraftViewBuilder<St, S> {
    /// Set the `lastEditAt` field (optional)
    pub fn last_edit_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `lastEditAt` field to an Option value (optional)
    pub fn maybe_last_edit_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: draft_view_state::State, S: BosStr> DraftViewBuilder<St, S> {
    /// Set the `title` field (optional)
    pub fn title(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `title` field to an Option value (optional)
    pub fn maybe_title(mut self, value: Option<S>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> DraftViewBuilder<St, S>
where
    St: draft_view_state::State,
    St::Uri: draft_view_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> DraftViewBuilder<draft_view_state::SetUri<St>, S> {
        self._fields.5 = Option::Some(value.into());
        DraftViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DraftViewBuilder<St, S>
where
    St: draft_view_state::State,
    St::Cid: draft_view_state::IsSet,
    St::CreatedAt: draft_view_state::IsSet,
    St::Uri: draft_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> DraftView<S> {
        DraftView {
            cid: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            edit_root: self._fields.2,
            last_edit_at: self._fields.3,
            title: self._fields.4,
            uri: self._fields.5.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>>,
    ) -> DraftView<S> {
        DraftView {
            cid: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            edit_root: self._fields.2,
            last_edit_at: self._fields.3,
            title: self._fields.4,
            uri: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_edit_listDrafts() -> 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("sh.weaver.edit.listDrafts"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("draftView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Hydrated view of a draft with edit state."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("editRoot"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("lastEditAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Extracted title if available from edit state",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("actor")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("actor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static("DID or handle of the actor"),
                                        ),
                                        format: Some(LexStringFormat::AtIdentifier),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

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

impl<S: BosStr> ListDrafts<S> {
    /// Create a new builder for this type
    pub fn builder() -> ListDraftsBuilder<list_drafts_state::Empty, S> {
        ListDraftsBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ListDraftsBuilder<St, S>
where
    St: list_drafts_state::State,
    St::Actor: list_drafts_state::IsUnset,
{
    /// Set the `actor` field (required)
    pub fn actor(
        mut self,
        value: impl Into<AtIdentifier<S>>,
    ) -> ListDraftsBuilder<list_drafts_state::SetActor<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ListDraftsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St: list_drafts_state::State, S: BosStr> ListDraftsBuilder<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, S: BosStr> ListDraftsBuilder<St, S>
where
    St: list_drafts_state::State,
    St::Actor: list_drafts_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ListDrafts<S> {
        ListDrafts {
            actor: self._fields.0.unwrap(),
            cursor: self._fields.1,
            limit: self._fields.2,
        }
    }
}