// @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;

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DraftView<'a> {
    #[serde(borrow)]
    pub cid: Cid<'a>,
    pub created_at: Datetime,
    ///Associated edit root if one exists
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub edit_root: Option<StrongRef<'a>>,
    #[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")]
    #[serde(borrow)]
    pub title: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListDrafts<'a> {
    #[serde(borrow)]
    pub actor: AtIdentifier<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    ///Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListDraftsOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub drafts: Vec<list_drafts::DraftView<'a>>,
}

impl<'a> LexiconSchema for DraftView<'a> {
    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 type for sh.weaver.edit.listDrafts
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<'de> = ListDraftsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

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

/// Endpoint type for sh.weaver.edit.listDrafts
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<'de> = ListDrafts<'de>;
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Cid = Set<members::cid>;
        type CreatedAt = S::CreatedAt;
        type Uri = S::Uri;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Cid = S::Cid;
        type CreatedAt = Set<members::created_at>;
        type Uri = S::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Cid = S::Cid;
        type CreatedAt = S::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<'a, S: draft_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Cid<'a>>,
        Option<Datetime>,
        Option<StrongRef<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<AtUri<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: draft_view_state::State> DraftViewBuilder<'a, S> {
    /// Set the `editRoot` field (optional)
    pub fn edit_root(mut self, value: impl Into<Option<StrongRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: draft_view_state::State> DraftViewBuilder<'a, 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<'a, S: draft_view_state::State> DraftViewBuilder<'a, S> {
    /// Set the `title` field (optional)
    pub fn title(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `title` field to an Option value (optional)
    pub fn maybe_title(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<'a, S> DraftViewBuilder<'a, S>
where
    S: draft_view_state::State,
    S::Cid: draft_view_state::IsSet,
    S::CreatedAt: draft_view_state::IsSet,
    S::Uri: draft_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> DraftView<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> DraftView<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetActor<S> {}
    impl<S: State> State for SetActor<S> {
        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<'a, S: list_drafts_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtIdentifier<'a>>, Option<CowStr<'a>>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: list_drafts_state::State> ListDraftsBuilder<'a, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = 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.1 = value;
        self
    }
}

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